Class: SyntaxTree::RBS::Attribute
- Inherits:
-
Object
- Object
- SyntaxTree::RBS::Attribute
- Defined in:
- lib/syntax_tree/rbs/members.rb
Overview
Prints out an attr_* meta method, which looks like: attr_accessor foo: Foo attr_reader foo: Foo attr_writer foo: Foo
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #format(q) ⇒ Object
-
#initialize(type, node) ⇒ Attribute
constructor
A new instance of Attribute.
- #pretty_print(q) ⇒ Object
Constructor Details
#initialize(type, node) ⇒ Attribute
Returns a new instance of Attribute.
12 13 14 15 |
# File 'lib/syntax_tree/rbs/members.rb', line 12 def initialize(type, node) @type = type @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
10 11 12 |
# File 'lib/syntax_tree/rbs/members.rb', line 10 def node @node end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/syntax_tree/rbs/members.rb', line 10 def type @type end |
Instance Method Details
#format(q) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/syntax_tree/rbs/members.rb', line 17 def format(q) q.group do q.text("#{node.visibility} ") if node.visibility q.text("attr_#{type} ") q.text("self.") if node.kind == :singleton q.text(node.name) if node.ivar_name == false q.text("()") elsif node.ivar_name q.text("(") q.text(node.ivar_name) q.text(")") end q.text(": ") node.type.format(q) end end |
#pretty_print(q) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/syntax_tree/rbs/members.rb', line 37 def pretty_print(q) if node.kind == :singleton q.breakable q.text("singleton") end q.breakable q.text("name=") q.pp(node.name) if node.visibility q.breakable q.text("visibility=") q.pp(node.visibility) end unless node.ivar_name.nil? q.breakable q.text("ivar_name=") q.pp(node.ivar_name) end q.breakable q.text("type=") q.pp(node.type) end |