Module: Hanswurst::MethodMissing

Included in:
Hanswurst
Defined in:
lib/hanswurst/method_missing.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &code) ⇒ Object

dispatches self.role calls and self.role= setters



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hanswurst/method_missing.rb', line 4

def method_missing(meth, *args, &code)
  value = args.first
  case meth
  when /^([^=]+)\=$/ # obj.role = ... # => we set a role
    role=$1
    if value.class == Hanswurst::As
      return self.send meth, value._role
    end
    add_role(role, value.class) unless role_exists?(role)
    set_role(role, value) if role_exists?(role)
    return as(meth)
  else
    return as(meth) if role_exists?(meth.to_s)
    return super if meth == :hanswurst_data_will_change!
    return nil
  end
  super
end