Module: Doodle::SelfClass
- Included in:
- BaseMethods
- Defined in:
- lib/doodle.rb
Overview
provides more direct access to the singleton class and a way to treat singletons, Modules and Classes equally in a meta context
Instance Method Summary collapse
-
#sc_eval(*args, &block) ⇒ Object
evaluate in class context of self, whether Class, Module or singleton.
-
#singleton_class(&block) ⇒ Object
return the ‘singleton class’ of an object, optionally executing a block argument in the (module/class) context of that object.
Instance Method Details
#sc_eval(*args, &block) ⇒ Object
evaluate in class context of self, whether Class, Module or singleton
237 238 239 240 241 242 243 244 |
# File 'lib/doodle.rb', line 237 def sc_eval(*args, &block) if self.kind_of?(Module) klass = self else klass = self.singleton_class end klass.module_eval(*args, &block) end |
#singleton_class(&block) ⇒ Object
return the ‘singleton class’ of an object, optionally executing a block argument in the (module/class) context of that object
231 232 233 234 235 |
# File 'lib/doodle.rb', line 231 def singleton_class(&block) sc = class << self; self; end sc.module_eval(&block) if block_given? sc end |