Module: Rubymisc::Object
- Defined in:
- lib/rubymisc/ext/object.rb
Instance Method Summary collapse
Instance Method Details
#and_try ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubymisc/ext/object.rb', line 21 def and_try _and_try_functor = BasicObject.new (class << _and_try_functor; self; end).module_eval do attr_accessor :delegate_to def method_missing(method, *args, &block) delegate_to ? delegate_to.__send__(method, *args, &block) : delegate_to end end _and_try_functor.delegate_to = self _and_try_functor end |
#in?(collection) ⇒ Boolean
5 6 7 |
# File 'lib/rubymisc/ext/object.rb', line 5 def in?(collection) collection.respond_to?(:include?) ? collection.include?(self) : false end |
#not ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rubymisc/ext/object.rb', line 9 def not _not_functor = ->(op, *a, &b) { !self.__send__(op, *a, &b) } _not_functor.singleton_class.module_eval <<-CODE def method_missing(method, *args, &block) call method, *args, &block end CODE _not_functor end |