Class: NForm::CoercionSet

Inherits:
Object
  • Object
show all
Defined in:
lib/nform/coercions.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/nform/coercions.rb', line 27

def method_missing(name,*args,&block)
  if set[name.to_sym]
    set[name.to_sym].call(*args,&block)
  else
    super
  end
end

Instance Method Details

#[](key) ⇒ Object



7
8
9
# File 'lib/nform/coercions.rb', line 7

def [](key)
  set[key.to_sym]
end

#[]=(key, val) ⇒ Object



11
12
13
# File 'lib/nform/coercions.rb', line 11

def []=(key,val)
  set[key.to_sym] = val
end

#fetch(key) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/nform/coercions.rb', line 15

def fetch(key)
  if v = set[key]
    v
  else
    raise Error, "Undefined coercion: #{key}"
  end
end

#respond_to_missing?(name) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/nform/coercions.rb', line 23

def respond_to_missing?(name,*)
  set.has_key?(name.to_sym)
end