Class: Parlour::RbiGenerator::Constant
- Defined in:
- lib/parlour/rbi_generator/constant.rb
Overview
Represents a constant definition.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from RbiObject
#comments, #generated_by, #generator, #name
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if this instance is equal to another extend.
-
#describe ⇒ String
Returns a human-readable brief string description of this code.
-
#generate_rbi(indent_level, options) ⇒ Array<String>
Generates the RBI lines for this constant.
-
#initialize(generator, name: '', value: '', &block) ⇒ Constant
constructor
Creates a new constant definition.
-
#merge_into_self(others) ⇒ void
Given an array of Constant instances, merges them into this one.
-
#mergeable?(others) ⇒ Boolean
Given an array of Constant instances, returns true if they may be merged into this instance using #merge_into_self.
Methods inherited from RbiObject
Constructor Details
#initialize(generator, name: '', value: '', &block) ⇒ Constant
Creates a new constant definition.
18 19 20 21 22 |
# File 'lib/parlour/rbi_generator/constant.rb', line 18 def initialize(generator, name: '', value: '', &block) super(generator, name) @value = value yield_self(&block) if block end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
26 27 28 |
# File 'lib/parlour/rbi_generator/constant.rb', line 26 def value @value end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if this instance is equal to another extend.
34 35 36 |
# File 'lib/parlour/rbi_generator/constant.rb', line 34 def ==(other) Constant === other && name == other.name && value == other.value end |
#describe ⇒ String
Returns a human-readable brief string description of this code.
89 90 91 |
# File 'lib/parlour/rbi_generator/constant.rb', line 89 def describe "Constant (#{name} = #{value})" end |
#generate_rbi(indent_level, options) ⇒ Array<String>
Generates the RBI lines for this constant.
49 50 51 |
# File 'lib/parlour/rbi_generator/constant.rb', line 49 def generate_rbi(indent_level, ) [.indented(indent_level, "#{name} = #{value}")] end |
#merge_into_self(others) ⇒ void
This method returns an undefined value.
Given an array of Parlour::RbiGenerator::Constant instances, merges them into this one. This particular implementation will simply do nothing, as instances are only mergeable if they are indentical. You MUST ensure that #mergeable? is true for those instances.
81 82 83 |
# File 'lib/parlour/rbi_generator/constant.rb', line 81 def merge_into_self(others) # We don't need to change anything! We only merge identical constants end |
#mergeable?(others) ⇒ Boolean
Given an array of Parlour::RbiGenerator::Constant instances, returns true if they may be merged into this instance using #merge_into_self. This is always false.
64 65 66 |
# File 'lib/parlour/rbi_generator/constant.rb', line 64 def mergeable?(others) others.all? { |other| self == other } end |