Class: EacRubyUtils::CommonConstructor::SuperArgs
- Defined in:
- lib/eac_ruby_utils/common_constructor.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#common_constructor ⇒ Object
readonly
Returns the value of attribute common_constructor.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #auto_result ⇒ Object
-
#initialize(common_constructor, args, object) ⇒ SuperArgs
constructor
A new instance of SuperArgs.
- #result ⇒ Object
- #result_from_options ⇒ Object
- #sub_args ⇒ Object
- #super_arg_index(name) ⇒ Object
- #super_method ⇒ Object
Constructor Details
#initialize(common_constructor, args, object) ⇒ SuperArgs
143 144 145 146 147 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 143 def initialize(common_constructor, args, object) @common_constructor = common_constructor @args = args @object = object end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
141 142 143 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 141 def args @args end |
#common_constructor ⇒ Object (readonly)
Returns the value of attribute common_constructor.
141 142 143 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 141 def common_constructor @common_constructor end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
141 142 143 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 141 def object @object end |
Instance Method Details
#auto_result ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 149 def auto_result r = [] sub_args.each do |name, value| i = super_arg_index(name) r[i] = value if i end r end |
#result ⇒ Object
158 159 160 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 158 def result || auto_result end |
#result_from_options ⇒ Object
162 163 164 165 166 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 162 def return unless common_constructor.super_args object.instance_exec(&common_constructor.super_args) end |
#sub_args ⇒ Object
168 169 170 171 172 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 168 def sub_args common_constructor.args.each_with_index.map do |name, index| [name, args[index]] end.to_h end |
#super_arg_index(name) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 174 def super_arg_index(name) super_method.parameters.each_with_index do |arg, index| return index if arg[1] == name end nil end |
#super_method ⇒ Object
181 182 183 |
# File 'lib/eac_ruby_utils/common_constructor.rb', line 181 def super_method object.class.superclass ? object.class.superclass.instance_method(:initialize) : nil end |