Class: Parameters::ClassParam

Inherits:
Param show all
Defined in:
lib/parameters/class_param.rb

Instance Attribute Summary collapse

Attributes inherited from Param

#description, #name, #type

Instance Method Summary collapse

Methods inherited from Param

#coerce

Constructor Details

#initialize(name, type = nil, description = nil, value = nil) ⇒ ClassParam

Creates a new ClassParam object.

Parameters:

  • name (Symbol, String)

    The name of the class parameter.

  • type (Class, Array[Class]) (defaults to: nil)

    The enforced type of the class parameter.

  • description (String, nil) (defaults to: nil)

    The description of the class parameter.

  • value (Object, nil) (defaults to: nil)

    The default value of the class parameter.



24
25
26
27
28
# File 'lib/parameters/class_param.rb', line 24

def initialize(name,type=nil,description=nil,value=nil)
  super(name,type,description)

  @value = value
end

Instance Attribute Details

#valueObject

Default value of the class parameter



7
8
9
# File 'lib/parameters/class_param.rb', line 7

def value
  @value
end

Instance Method Details

#inspectString

Inspects the class parameter.

Returns:

  • (String)

    Inspection of the class params value.



87
88
89
# File 'lib/parameters/class_param.rb', line 87

def inspect
  "#<#{self.class}: #{@value.inspect}>"
end

#to_instance(object) ⇒ InstanceParam

Creates an instance parameter from the class param.

Parameters:

  • object (Object)

    The object the instance parameter should be connected to.

Returns:

Since:

  • 0.3.0



58
59
60
61
62
63
64
65
66
# File 'lib/parameters/class_param.rb', line 58

def to_instance(object)
  InstanceParam.new(
    object,
    @name,
    @type,
    @description,
    @value
  )
end

#to_sString

Returns The representation of the class param.

Returns:

  • (String)

    The representation of the class param.



72
73
74
75
76
77
78
79
# File 'lib/parameters/class_param.rb', line 72

def to_s
  text = @name.to_s

  text << "\t[#{@value.inspect}]" if @value
  text << "\t#{@description}"     if @description

  return text
end