Module: Trick::Value

Defined in:
lib/trick/value.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/trick/value.rb', line 5

def self.extended(base)
  if base.superclass == Struct
    base.define_singleton_method(:[]) do |*args, &block|
      curry(base.members.count)[*args, &block]
    end
  end
end

Instance Method Details

#[](*args, &block) ⇒ Object



21
22
23
# File 'lib/trick/value.rb', line 21

def [](*args, &block)
  curry[*args, &block]
end

#call(*args) ⇒ Object



25
26
27
# File 'lib/trick/value.rb', line 25

def call(*args)
  new(*args)
end

#curry(arity = nil) ⇒ Object



17
18
19
# File 'lib/trick/value.rb', line 17

def curry(arity = nil)
  to_proc.curry(arity || instance_method(:initialize).arity)
end

#to_procObject



13
14
15
# File 'lib/trick/value.rb', line 13

def to_proc
  method(:new).to_proc
end