Module: Stunted::Defn

Defined in:
lib/stunted/chaining.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defn(name, fn = nil, &block) ⇒ Object

Note: if you use a block with defn, you get block semantics. In particular, don’t try to return from such a block.



7
8
9
10
11
12
13
14
15
# File 'lib/stunted/chaining.rb', line 7

def defn(name, fn = nil, &block)
  if fn
    define_method(name) { fn }
  else
    puts "Lambda rigamarole could be just { block }"
    define_method(name) { lambda(&block) }  # Todo: why is this lambda rigamarole required?
  end
  module_function name if respond_to?(:module_function, true) 
end

Instance Method Details

#defn(name, fn = nil, &block) ⇒ Object

Note: if you use a block with defn, you get block semantics. In particular, don’t try to return from such a block.



7
8
9
10
11
12
13
14
15
# File 'lib/stunted/chaining.rb', line 7

def defn(name, fn = nil, &block)
  if fn
    define_method(name) { fn }
  else
    puts "Lambda rigamarole could be just { block }"
    define_method(name) { lambda(&block) }  # Todo: why is this lambda rigamarole required?
  end
  module_function name if respond_to?(:module_function, true) 
end