Class: Klam::Cons
Instance Attribute Summary collapse
-
#hd ⇒ Object
readonly
Returns the value of attribute hd.
-
#tl ⇒ Object
readonly
Returns the value of attribute tl.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each ⇒ Object
- #hash ⇒ Object
-
#initialize(hd, tl) ⇒ Cons
constructor
A new instance of Cons.
Constructor Details
#initialize(hd, tl) ⇒ Cons
Returns a new instance of Cons.
6 7 8 9 |
# File 'lib/klam/cons.rb', line 6 def initialize(hd, tl) @hd = hd @tl = tl end |
Instance Attribute Details
#hd ⇒ Object (readonly)
Returns the value of attribute hd.
4 5 6 |
# File 'lib/klam/cons.rb', line 4 def hd @hd end |
#tl ⇒ Object (readonly)
Returns the value of attribute tl.
4 5 6 |
# File 'lib/klam/cons.rb', line 4 def tl @tl end |
Instance Method Details
#==(other) ⇒ Object
11 12 13 |
# File 'lib/klam/cons.rb', line 11 def ==(other) other.instance_of?(Cons) && other.hd == @hd && other.tl == @tl end |
#each ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/klam/cons.rb', line 19 def each x = self until x == Klam::Primitives::Lists::EMPTY_LIST yield x.hd x = x.tl end end |
#hash ⇒ Object
15 16 17 |
# File 'lib/klam/cons.rb', line 15 def hash [@hd, @tl].hash end |