Class: Initializer::Parameter
- Inherits:
-
Object
- Object
- Initializer::Parameter
- Defined in:
- lib/initializer/parameter.rb
Defined Under Namespace
Classes: StringDefaultValue
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#visibility ⇒ Object
readonly
Returns the value of attribute visibility.
Class Method Summary collapse
Instance Method Summary collapse
- #argument_definition ⇒ Object
- #default_value(value) ⇒ Object
-
#initialize(name, visibility) ⇒ Parameter
constructor
A new instance of Parameter.
Constructor Details
#initialize(name, visibility) ⇒ Parameter
Returns a new instance of Parameter.
7 8 9 10 |
# File 'lib/initializer/parameter.rb', line 7 def initialize(name, visibility) @name = name @visibility = visibility end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
5 6 7 |
# File 'lib/initializer/parameter.rb', line 5 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/initializer/parameter.rb', line 3 def name @name end |
#visibility ⇒ Object (readonly)
Returns the value of attribute visibility.
4 5 6 |
# File 'lib/initializer/parameter.rb', line 4 def visibility @visibility end |
Class Method Details
.build(name, visibility, default = NO_DEFAULT_VALUE) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/initializer/parameter.rb', line 35 def self.build(name, visibility, default = NO_DEFAULT_VALUE) instance = new(name, visibility) unless default.eql?(NO_DEFAULT_VALUE) default = build_default_value(default) instance.default_value(default) end instance end |
.build_default_value(value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/initializer/parameter.rb', line 22 def self.build_default_value(value) result = value unless result.respond_to?(:code_fragment) if [String, Symbol].include?(result.class) result = StringDefaultValue.new(result.to_s) else result = Statement.new(result) end end result end |
Instance Method Details
#argument_definition ⇒ Object
16 17 18 19 20 |
# File 'lib/initializer/parameter.rb', line 16 def argument_definition return "#{@name} = #{default.code_fragment}" if @default return @name end |
#default_value(value) ⇒ Object
12 13 14 |
# File 'lib/initializer/parameter.rb', line 12 def default_value(value) @default = value end |