Module: Eco::Language::Delegation::DelegatedClass
- Defined in:
- lib/eco/language/delegation/delegated_class.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #delegated_class ⇒ Object
-
#initialize(*args, **kargs, &block) ⇒ Object
It allows to chain delegators, when the first parameter is an instance of
delegated_class. - #instance_of?(base) ⇒ Boolean
- #is_a?(base) ⇒ Boolean
- #new ⇒ Object
- #of_kind?(obj) ⇒ Boolean
Instance Method Details
#delegated_class ⇒ Object
54 55 56 |
# File 'lib/eco/language/delegation/delegated_class.rb', line 54 def delegated_class self.class.delegated_class end |
#initialize(*args, **kargs, &block) ⇒ Object
Note:
it also allows to create an instance of delegated_class
on initialization.
It allows to chain delegators, when the first parameter is an
instance of delegated_class.
47 48 49 50 51 52 |
# File 'lib/eco/language/delegation/delegated_class.rb', line 47 def initialize(*args, **kargs, &block) obj = args.first obj = new(*args, **kargs, &block) unless of_kind?(obj) super(obj) end |
#instance_of?(base) ⇒ Boolean
78 79 80 81 82 |
# File 'lib/eco/language/delegation/delegated_class.rb', line 78 def instance_of?(base) return true if base == delegated_class super end |
#is_a?(base) ⇒ Boolean
70 71 72 73 74 75 76 |
# File 'lib/eco/language/delegation/delegated_class.rb', line 70 def is_a?(base) return true if super return false unless delegated_class return true if delegated_class <= base false end |
#new ⇒ Object
58 59 60 |
# File 'lib/eco/language/delegation/delegated_class.rb', line 58 def new(...) delegated_class.new(...) end |
#of_kind?(obj) ⇒ Boolean
62 63 64 65 66 67 68 |
# File 'lib/eco/language/delegation/delegated_class.rb', line 62 def of_kind?(obj) return true if obj.is_a?(delegated_class) return false unless obj.is_a(Delegator) return true if obj.__get_obj__.is_a?(delegated_class) false end |