Class: MethodArgs::ArgList::Arg
- Inherits:
-
Object
- Object
- MethodArgs::ArgList::Arg
- Defined in:
- lib/method_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_value(receiver = nil) ⇒ 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.
26 27 28 |
# File 'lib/method_args.rb', line 26 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.
23 24 25 |
# File 'lib/method_args.rb', line 23 def arg_list @arg_list end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/method_args.rb', line 24 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
24 25 26 |
# File 'lib/method_args.rb', line 24 def type @type end |
Instance Method Details
#default_value(receiver = nil) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/method_args.rb', line 42 def default_value(receiver = nil) return nil if @default.nil? receiver ||= arg_list.owning_method.receiver if arg_list.owning_method.respond_to?(: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 #{@cls.name}." unless receiver.is_a?(arg_list.cls) receiver.instance_eval(@default) end |
#optional? ⇒ Boolean
34 35 36 |
# File 'lib/method_args.rb', line 34 def optional? @type == :optional end |
#required? ⇒ Boolean
30 31 32 |
# File 'lib/method_args.rb', line 30 def required? @type == :required end |
#splat? ⇒ Boolean
38 39 40 |
# File 'lib/method_args.rb', line 38 def splat? @type == :splat end |