Module: RolePlaying::Context::ClassMethods
- Defined in:
- lib/role_playing/context.rb
Instance Method Summary collapse
-
#role(name, parent = nil, &block) ⇒ Object
this seemed too dangerous to use it enabled us to use Constants when defining roles but would also not warn about missing constants - which is pretty bad def const_missing(sym) sym end.
Instance Method Details
#role(name, parent = nil, &block) ⇒ Object
this seemed too dangerous to use it enabled us to use Constants when defining roles but would also not warn about missing constants - which is pretty bad def const_missing(sym)
sym
end
14 15 16 17 18 19 20 21 22 |
# File 'lib/role_playing/context.rb', line 14 def role(name, parent=nil, &block) parent = parent || ::Role klass = Class.new(parent, &block) define_method(name) do |*args, &role_block| instance = klass.new(*args) role_block.nil? ? instance : role_block.call(instance) end const_set name, klass end |