Class: LazyList::Base
- Inherits:
-
Object
- Object
- LazyList::Base
- Includes:
- Enumerable
- Defined in:
- lib/lazy_list/base.rb
Direct Known Subclasses
Instance Method Summary collapse
- #each {|first| ... } ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(list = nil) ⇒ Base
constructor
A new instance of Base.
- #inspect ⇒ Object
- #prepend(a) ⇒ Object
- #rest ⇒ Object
Constructor Details
Instance Method Details
#each {|first| ... } ⇒ Object
32 33 34 35 36 |
# File 'lib/lazy_list/base.rb', line 32 def each(&block) return if first.nil? yield first rest.each(&block) end |
#empty? ⇒ Boolean
10 11 12 |
# File 'lib/lazy_list/base.rb', line 10 def empty? @has_contents ||= false end |
#first ⇒ Object
24 25 26 |
# File 'lib/lazy_list/base.rb', line 24 def first LazyList.car(@list).call end |
#inspect ⇒ Object
14 15 16 |
# File 'lib/lazy_list/base.rb', line 14 def inspect "[" + (map { |element| element.inspect }.join(", ")) + "]" end |