Class: MethodArgs::ArgList::Arg

Inherits:
Object
  • Object
show all
Defined in:
lib/method_args.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_listObject

Returns the value of attribute arg_list.



23
24
25
# File 'lib/method_args.rb', line 23

def arg_list
  @arg_list
end

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/method_args.rb', line 24

def name
  @name
end

#typeObject (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

Returns:

  • (Boolean)


34
35
36
# File 'lib/method_args.rb', line 34

def optional?
  @type == :optional
end

#required?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/method_args.rb', line 30

def required?
  @type == :required
end

#splat?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/method_args.rb', line 38

def splat?
  @type == :splat
end