Module: AyeCommander::Ivar::Readable
- Included in:
- Command, Resultable::Result
- Defined in:
- lib/aye_commander/ivar.rb
Overview
Helps a command and result respond to read methods of instance variables This functionality is divided into two different modules since commander includes both, but result only includes Readable
Instance Method Summary collapse
-
#method_missing(name, *args) ⇒ Object
A command will only respond to a read instance variable if it receives a valid instance variable name that is already defined within the command or result.
-
#remove!(name) ⇒ Object
This helps remove an instance variable name from the current command.
-
#to_ivar(name) ⇒ Object
Transforms the received name to instance variable form.
-
#to_nvar(name) ⇒ Object
Transforms the received name to normal variable form.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
A command will only respond to a read instance variable if it receives a valid instance variable name that is already defined within the command or result.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aye_commander/ivar.rb', line 34 def method_missing(name, *args) var_name = to_ivar(name) if instance_variable_defined? var_name self.class.define_missing_reader(name) instance_variable_get var_name else super end rescue NameError super end |
Instance Method Details
#remove!(name) ⇒ Object
This helps remove an instance variable name from the current command. Consider using the .returns method instead.
48 49 50 |
# File 'lib/aye_commander/ivar.rb', line 48 def remove!(name) remove_instance_variable to_ivar(name) end |
#to_ivar(name) ⇒ Object
Transforms the received name to instance variable form
53 54 55 |
# File 'lib/aye_commander/ivar.rb', line 53 def to_ivar(name) self.class.to_ivar(name) end |
#to_nvar(name) ⇒ Object
Transforms the received name to normal variable form
58 59 60 |
# File 'lib/aye_commander/ivar.rb', line 58 def to_nvar(name) self.class.to_nvar(name) end |