Module: Object::ObjectExtensions

Included in:
Object
Defined in:
lib/ragweed/utils.rb

Instance Method Summary collapse

Instance Method Details

#callable?Boolean

Returns:

  • (Boolean)


55
# File 'lib/ragweed/utils.rb', line 55

def callable?; respond_to? :call; end

#deriveObject

while X remains callable, keep calling it to get its value



59
60
61
62
63
64
65
66
# File 'lib/ragweed/utils.rb', line 59

def derive
  # also, don't drink and derive
  x = self
  while x.callable?
    x = x()
  end
  return x
end

#meta_def(name, &blk) ⇒ Object



39
# File 'lib/ragweed/utils.rb', line 39

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

#meta_eval(&blk) ⇒ Object



38
# File 'lib/ragweed/utils.rb', line 38

def meta_eval(&blk) metaclass.instance_eval &blk; end

#metaclassObject

Every object has a “singleton” class, which you can think of as the class (ie, 1.metaclass =~ Fixnum) — but that you can modify and extend without fucking up the actual class.



37
# File 'lib/ragweed/utils.rb', line 37

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

#mymethodsObject

This is from Topher Cyll’s Stupd IRB tricks



51
52
53
# File 'lib/ragweed/utils.rb', line 51

def mymethods
  (self.methods - self.class.superclass.methods).sort
end

#number?Boolean

Returns:

  • (Boolean)


56
# File 'lib/ragweed/utils.rb', line 56

def number?; kind_of? Numeric; end

#through(meth, *args) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/ragweed/utils.rb', line 42

def through(meth, *args)
  if respond_to? meth
    send(meth, *args)
  else
    self
  end
end

#try(meth, *args) ⇒ Object



40
# File 'lib/ragweed/utils.rb', line 40

def try(meth, *args); send(meth, *args) if respond_to? meth; end