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

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.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/aye_commander/ivar.rb', line 45

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.



59
60
61
# File 'lib/aye_commander/ivar.rb', line 59

def remove!(name)
  remove_instance_variable to_ivar(name)
end

#to_ivar(name) ⇒ Object

Transforms the received name to instance variable form



64
65
66
# File 'lib/aye_commander/ivar.rb', line 64

def to_ivar(name)
  self.class.to_ivar(name)
end

#to_nvar(name) ⇒ Object

Transforms the received name to normal variable form



69
70
71
# File 'lib/aye_commander/ivar.rb', line 69

def to_nvar(name)
  self.class.to_nvar(name)
end