Class: EacRubyUtils::CommonConstructor::SuperArgs
- Defined in:
- lib/eac_ruby_utils/common_constructor/super_args.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#class_initialize ⇒ Object
readonly
Returns the value of attribute class_initialize.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #auto_result ⇒ Object
-
#initialize(class_initialize, 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(class_initialize, args, object) ⇒ SuperArgs
Returns a new instance of SuperArgs.
12 13 14 15 16 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 12 def initialize(class_initialize, args, object) @class_initialize = class_initialize @args = args @object = object end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 8 def args @args end |
#class_initialize ⇒ Object (readonly)
Returns the value of attribute class_initialize.
8 9 10 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 8 def class_initialize @class_initialize end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
8 9 10 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 8 def object @object end |
Instance Method Details
#auto_result ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 18 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
27 28 29 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 27 def result || auto_result end |
#result_from_options ⇒ Object
31 32 33 34 35 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 31 def return unless common_constructor.super_args object.instance_exec(&common_constructor.super_args) end |
#sub_args ⇒ Object
37 38 39 40 41 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 37 def sub_args common_constructor.args.each_with_index.to_h do |name, index| [name, args[index]] end end |
#super_arg_index(name) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 43 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
50 51 52 |
# File 'lib/eac_ruby_utils/common_constructor/super_args.rb', line 50 def super_method class_initialize.klass.superclass&.instance_method(:initialize) end |