Module: EnumArgs::ProxiedEnumerable

Defined in:
lib/enum_args/proxied_enumerable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.on_enumerable_methods(on, &blk) ⇒ Object



58
59
60
61
62
# File 'lib/enum_args/proxied_enumerable.rb', line 58

def self.on_enumerable_methods(on, &blk)
  (Enumerable.instance_methods + [:each]).each do |m|
    on.send :define_method, m, &blk
  end
end

.prepended(base) ⇒ Object



52
53
54
55
56
# File 'lib/enum_args/proxied_enumerable.rb', line 52

def self.prepended(base)
  # including Enumerable is just so that obj#is_a? Enumerable returns true
  base.include Enumerable
  base.singleton_class.prepend ClassMethods
end

Instance Method Details

#initialize(*args, &blk) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/enum_args/proxied_enumerable.rb', line 68

def initialize(*args, &blk)
  klass = self.class
  name = klass.enum_args_accessor_method
  instance_variable_set(
    "@#{name}",
    EnumArgs::Proxy.new(self, klass.enum_args_method, *klass.enum_args_default_args,
                        using: klass.enum_args_default_using, cache: klass.enum_args_cache)
  )
  define_singleton_method(name) do
    instance_variable_get("@#{name}")
  end
  super
end