Class: DynamicSchema::Receiver::Value
- Defined in:
- lib/dynamic_schema/receiver/value.rb
Instance Method Summary collapse
-
#initialize(target) ⇒ Value
constructor
A new instance of Value.
- #method_missing(method_name, *args, &block) ⇒ Object
Methods inherited from Base
const_missing, #evaluate, #inspect, #nil?, #pretty_print, #to_s
Constructor Details
#initialize(target) ⇒ Value
Returns a new instance of Value.
6 7 8 |
# File 'lib/dynamic_schema/receiver/value.rb', line 6 def initialize( target ) @target = target end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/dynamic_schema/receiver/value.rb', line 10 def method_missing( method_name, *args, &block ) writer_method = :"#{ method_name }=" unless @target.respond_to?( writer_method ) ::Kernel.raise ::NoMethodError, "The attribute '#{ method_name }' cannot be assigned because '#{ @target.class.name }' does not define '#{ writer_method }'." end if args.length != 1 ::Kernel.raise ::ArgumentError, "The attribute '#{ method_name }' requires 1 argument but #{ args.length } was given." end @target.public_send( writer_method, args.first ) end |