Class: Estreet::BlockStatement
- Defined in:
- lib/estreet/block_statement.rb
Instance Attribute Summary collapse
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
Attributes inherited from Node
Class Method Summary collapse
Instance Method Summary collapse
-
#<<(statement) ⇒ Object
Add another statement to the end of the receiver block.
- #attributes ⇒ Object
-
#initialize(*statements) ⇒ BlockStatement
constructor
A new instance of BlockStatement.
- #to_block ⇒ Object
Methods inherited from Statement
Methods inherited from Node
Constructor Details
#initialize(*statements) ⇒ BlockStatement
Returns a new instance of BlockStatement.
3 4 5 6 7 8 |
# File 'lib/estreet/block_statement.rb', line 3 def initialize(*statements) @statements = statements.map do |st| st.to_statement # raise TypeError, "Not a statement: #{st}" unless st.is_a? Statement end end |
Instance Attribute Details
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
35 36 37 |
# File 'lib/estreet/block_statement.rb', line 35 def statements @statements end |
Class Method Details
.flatten(*statements) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/estreet/block_statement.rb', line 23 def self.flatten(*statements) new(*statements.flat_map do |stmt| if stmt.is_a? self stmt.statements else stmt.to_statement end end) rescue NoMethodError => e raise TypeError, "Can't convert to statement: #{statements.inspect}" end |
Instance Method Details
#<<(statement) ⇒ Object
Add another statement to the end of the receiver block
19 20 21 |
# File 'lib/estreet/block_statement.rb', line 19 def <<(statement) self.class.flatten(self, statement) end |
#attributes ⇒ Object
10 11 12 |
# File 'lib/estreet/block_statement.rb', line 10 def attributes super.merge(body: @statements) end |
#to_block ⇒ Object
14 15 16 |
# File 'lib/estreet/block_statement.rb', line 14 def to_block self end |