Class: Hexp::List
Overview
A list of nodes
Class Method Summary collapse
-
.[](*args) ⇒ Hexp::List
Convenience constructor.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #append(*args) ⇒ Object
-
#eql?(other) ⇒ true, false
Value and type equality.
-
#initialize(nodes) ⇒ List
constructor
Create new Hexp::List.
-
#inspect ⇒ String
private
String representation.
-
#to_ary ⇒ Array<Hexp::Node>
Implicit conversion to Array.
- #to_html ⇒ Object
- #to_s ⇒ Object
Constructor Details
Class Method Details
.[](*args) ⇒ Hexp::List
Convenience constructor
36 37 38 |
# File 'lib/hexp/list.rb', line 36 def self.[](*args) new(args) end |
Instance Method Details
#+(other) ⇒ Object
93 94 95 |
# File 'lib/hexp/list.rb', line 93 def +(other) self.class[*to_ary, *other.to_ary] end |
#append(*args) ⇒ Object
97 98 99 |
# File 'lib/hexp/list.rb', line 97 def append(*args) self + args end |
#eql?(other) ⇒ true, false
Value and type equality
Hexp::List is mostly interchangeable with a plain Array, and so equality with ‘==` delegates to the underlying array, making `Hexp::List[] == []` true.
If you want a stronger comparison, than this version will compare both the value (in this case : contents), and the type.
85 86 87 |
# File 'lib/hexp/list.rb', line 85 def eql?(other) self == other && self.class == other.class end |
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
String representation
This delegates to the underlying array, so it’s not obvious from the output that this is a wrapping class. This is convenient when inspecting nested hexps, but probably something we want to solve differently.
49 50 51 |
# File 'lib/hexp/list.rb', line 49 def inspect __getobj__.inspect end |
#to_ary ⇒ Array<Hexp::Node>
Implicit conversion to Array
61 62 63 |
# File 'lib/hexp/list.rb', line 61 def to_ary __getobj__ end |
#to_html ⇒ Object
89 90 91 |
# File 'lib/hexp/list.rb', line 89 def to_html each_with_object('') {|n,s| s << n.to_html} end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/hexp-rails.rb', line 13 def to_s to_html.html_safe end |