Module: Object::ObjectExtensions
- Included in:
- Object
- Defined in:
- lib/ragweed/utils.rb
Instance Method Summary collapse
- #callable? ⇒ Boolean
-
#derive ⇒ Object
while X remains callable, keep calling it to get its value.
- #meta_def(name, &blk) ⇒ Object
- #meta_eval(&blk) ⇒ Object
-
#metaclass ⇒ Object
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.
-
#mymethods ⇒ Object
This is from Topher Cyll’s Stupd IRB tricks.
- #number? ⇒ Boolean
- #through(meth, *args) ⇒ Object
- #try(meth, *args) ⇒ Object
Instance Method Details
#callable? ⇒ Boolean
55 |
# File 'lib/ragweed/utils.rb', line 55 def callable?; respond_to? :call; end |
#derive ⇒ Object
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 (name, &blk) { define_method name, &blk }; end |
#meta_eval(&blk) ⇒ Object
38 |
# File 'lib/ragweed/utils.rb', line 38 def (&blk) .instance_eval &blk; end |
#metaclass ⇒ Object
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 ; class << self; self; end; end |
#mymethods ⇒ Object
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
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 |