Class: ParametersExtra::Args::Arg
- Inherits:
-
Object
- Object
- ParametersExtra::Args::Arg
- Defined in:
- lib/parameters_extra/args.rb
Instance Attribute Summary collapse
-
#arg_list ⇒ Object
Returns the value of attribute arg_list.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #default? ⇒ Boolean
- #default_value(*args) ⇒ Object
-
#initialize(name, type, default = nil) ⇒ Arg
constructor
A new instance of Arg.
- #optional? ⇒ Boolean
- #required? ⇒ Boolean
- #splat? ⇒ Boolean
Constructor Details
#initialize(name, type, default = nil) ⇒ Arg
Returns a new instance of Arg.
8 9 10 |
# File 'lib/parameters_extra/args.rb', line 8 def initialize(name, type, default = nil) @name, @type, @default = name, type, default end |
Instance Attribute Details
#arg_list ⇒ Object
Returns the value of attribute arg_list.
5 6 7 |
# File 'lib/parameters_extra/args.rb', line 5 def arg_list @arg_list end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/parameters_extra/args.rb', line 6 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/parameters_extra/args.rb', line 6 def type @type end |
Instance Method Details
#default? ⇒ Boolean
24 25 26 |
# File 'lib/parameters_extra/args.rb', line 24 def default? !@default.nil? end |
#default_value(*args) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/parameters_extra/args.rb', line 28 def default_value(*args) return nil if @default.nil? receiver ||= arg_list.owning_method.receiver raise "You must specify a receiver for the defaul value" if receiver.nil? raise "You must evaluate defaults in the context of a matching class. #{receiver.class.name} is not a #{arg_list.cls.name}." unless receiver.is_a?(arg_list.cls) receiver.instance_eval(@default) end |
#optional? ⇒ Boolean
16 17 18 |
# File 'lib/parameters_extra/args.rb', line 16 def optional? @type == :optional end |
#required? ⇒ Boolean
12 13 14 |
# File 'lib/parameters_extra/args.rb', line 12 def required? @type == :required end |
#splat? ⇒ Boolean
20 21 22 |
# File 'lib/parameters_extra/args.rb', line 20 def splat? @type == :splat end |