Class: Hamster::Realizable

Inherits:
Object
  • Object
show all
Includes:
List
Defined in:
lib/hamster/list.rb

Overview

Common behavior for other classes which implement various kinds of ‘List`s

Direct Known Subclasses

Partitioned, Splitter::Left, Splitter::Right

Constant Summary

Constants included from List

List::CADR

Instance Method Summary collapse

Methods included from List

#<<, [], #add, #append, #at, #break, #chunk, #clear, #combination, #cycle, #delete, #delete_at, #drop, #drop_while, #dup, #each, #each_chunk, empty, #eql?, #fill, #flat_map, #flatten, from_enum, #group_by, #hash, #indices, #init, #inits, #insert, #inspect, #intersperse, #last, #map, #merge, #merge_by, #partition, #permutation, #pop, #pretty_print, #respond_to?, #reverse, #rotate, #sample, #select, #slice, #sort, #sort_by, #span, #split_at, #subsequences, #tails, #take, #take_while, #to_list, #transpose, #union, #uniq, #zip

Methods included from Enumerable

#<=>, #==, #compact, #each_index, #grep, #grep_v, #group_by, #inspect, #join, #partition, #pretty_print, #product, #reject, #sort_by, #sum, #to_set

Methods included from Enumerable

#to_list

Constructor Details

#initializeRealizable

Returns a new instance of Realizable.



1387
1388
1389
# File 'lib/hamster/list.rb', line 1387

def initialize
  @head, @tail, @size = Undefined, Undefined, nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hamster::List

Instance Method Details

#cached_size?Boolean

Returns:

  • (Boolean)


1412
1413
1414
# File 'lib/hamster/list.rb', line 1412

def cached_size?
  @size != nil
end

#empty?Boolean

Returns:

  • (Boolean)


1402
1403
1404
1405
# File 'lib/hamster/list.rb', line 1402

def empty?
  realize if @head == Undefined
  @size == 0
end

#headObject Also known as: first



1391
1392
1393
1394
# File 'lib/hamster/list.rb', line 1391

def head
  realize if @head == Undefined
  @head
end

#realized?Boolean

Returns:

  • (Boolean)


1416
1417
1418
# File 'lib/hamster/list.rb', line 1416

def realized?
  @head != Undefined
end

#sizeObject Also known as: length



1407
1408
1409
# File 'lib/hamster/list.rb', line 1407

def size
  @size ||= super
end

#tailObject



1397
1398
1399
1400
# File 'lib/hamster/list.rb', line 1397

def tail
  realize if @tail == Undefined
  @tail
end