Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/rubyexts/try.rb,
lib/rubyexts/object.rb,
lib/rubyexts/try_dup.rb
Instance Method Summary collapse
-
#define_instance_method(*args) {|block| ... } ⇒ Object
Defines a instance method on class of the object.
-
#not_nil? ⇒ true, false
The opposite of
#nil?. -
#try(method, *args) {|block, optional| ... } ⇒ Object?
Unlike that method however, a
NoMethodErrorexception will not be raised andnilwill be returned instead, if the receiving object is anilobject or NilClass. - #try_dup ⇒ Object
Instance Method Details
#define_instance_method(*args) {|block| ... } ⇒ Object
Defines a instance method on class of the object.
33 34 35 |
# File 'lib/rubyexts/object.rb', line 33 def define_instance_method(*args, &block) self.class.send(:define_method, *args, &block) end |
#not_nil? ⇒ true, false
The opposite of #nil?.
9 10 11 |
# File 'lib/rubyexts/object.rb', line 9 def not_nil? not self.nil? end |
#try(method, *args) {|block, optional| ... } ⇒ Object?
Unlike that method however, a NoMethodError exception will not be raised and nil will be returned instead, if the receiving object is a nil object or NilClass.
Invokes the method identified by the symbol method, passing it any arguments and/or the block specified, just like the regular Ruby Object#send does.
20 21 22 |
# File 'lib/rubyexts/try.rb', line 20 def try(method, *args, &block) self.send(method, *args, &block) if self.respond_to?(method) end |
#try_dup ⇒ Object
22 23 24 |
# File 'lib/rubyexts/try_dup.rb', line 22 def try_dup self.dup end |