Class: Object

Inherits:
BasicObject
Defined in:
lib/hobosupport.rb,
lib/hobosupport/metaid.rb,
lib/hobosupport/enumerable.rb,
lib/hobosupport/methodcall.rb

Overview

Thanks to _why

Instance Method Summary collapse

Instance Method Details

#_?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/hobosupport/methodcall.rb', line 13

def _?()
  self
end

#in?(enum) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/hobosupport/enumerable.rb', line 84

def in?(enum)
  enum.include?(self)
end

#is_a?(*args) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/hobosupport.rb', line 25

def is_a?(*args)
  args.any? {|a| is_a_without_multiple_args?(a) }
end

#is_a_without_multiple_args?Object

Often nice to ask e.g. some_object.is_a?(Symbol, String)



24
# File 'lib/hobosupport.rb', line 24

alias_method :is_a_without_multiple_args?, :is_a?

#meta_def(name, &blk) ⇒ Object

Adds methods to a metaclass



24
25
26
# File 'lib/hobosupport/metaid.rb', line 24

def meta_def(name, &blk)
  meta_eval { define_method name, &blk }
end

#meta_eval(src = nil, &blk) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/hobosupport/metaid.rb', line 7

def meta_eval(src=nil, &blk)
  if src
    metaclass.instance_eval(src)
  else
    metaclass.instance_eval &blk
  end
end

#metaclassObject



5
# File 'lib/hobosupport/metaid.rb', line 5

def metaclass; class << self; self; end; end

#metaclass_eval(src = nil, &blk) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/hobosupport/metaid.rb', line 15

def metaclass_eval(src=nil, &blk)
  if src
    metaclass.class_eval(src)
  else
    metaclass.class_eval &blk
  end
end

#not_in?(enum) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/hobosupport/enumerable.rb', line 88

def not_in?(enum)
  not enum.include?(self)
end

#tryObject



17
18
19
# File 'lib/hobosupport/methodcall.rb', line 17

def try
  CallIfAvailable.new(self)
end