Class: Parlour::RbsGenerator::Constant
- Inherits:
-
RbsObject
- Object
- TypedObject
- RbsObject
- Parlour::RbsGenerator::Constant
- Defined in:
- lib/parlour/rbs_generator/constant.rb
Overview
Represents a constant definition.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from RbsObject
Attributes inherited from TypedObject
#comments, #generated_by, #name
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Returns true if this instance is equal to another extend.
- #describe_attrs ⇒ Object
-
#generate_rbs(indent_level, options) ⇒ Array<String>
Generates the RBS lines for this constant.
-
#initialize(generator, name, type:, &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 TypedObject
#add_comment, #describe, #describe_tree
Constructor Details
#initialize(generator, name, type:, &block) ⇒ Constant
Creates a new constant definition.
19 20 21 22 23 |
# File 'lib/parlour/rbs_generator/constant.rb', line 19 def initialize(generator, name, type:, &block) super(generator, name) @type = type yield_self(&block) if block end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
27 28 29 |
# File 'lib/parlour/rbs_generator/constant.rb', line 27 def type @type end |
Instance Method Details
#==(other) ⇒ Boolean
Returns true if this instance is equal to another extend.
35 36 37 |
# File 'lib/parlour/rbs_generator/constant.rb', line 35 def ==(other) Constant === other && name == other.name && type == other.type end |
#describe_attrs ⇒ Object
87 88 89 |
# File 'lib/parlour/rbs_generator/constant.rb', line 87 def describe_attrs [{type: type}] # avoid quotes end |
#generate_rbs(indent_level, options) ⇒ Array<String>
Generates the RBS lines for this constant.
50 51 52 |
# File 'lib/parlour/rbs_generator/constant.rb', line 50 def generate_rbs(indent_level, ) [.indented(indent_level, "#{name}: #{String === @type ? @type : @type.generate_rbs}")] end |
#merge_into_self(others) ⇒ void
This method returns an undefined value.
Given an array of Parlour::RbsGenerator::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.
82 83 84 |
# File 'lib/parlour/rbs_generator/constant.rb', line 82 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::RbsGenerator::Constant instances, returns true if they may be merged into this instance using #merge_into_self. This is always false.
65 66 67 |
# File 'lib/parlour/rbs_generator/constant.rb', line 65 def mergeable?(others) others.all? { |other| self == other } end |