Class: Fir::Lines

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fir/lines.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*members) ⇒ Lines

Returns a new instance of Lines.



9
10
11
# File 'lib/fir/lines.rb', line 9

def initialize(*members)
  @members = members
end

Instance Attribute Details

#membersObject (readonly)

Returns the value of attribute members.



7
8
9
# File 'lib/fir/lines.rb', line 7

def members
  @members
end

Class Method Details

.blankObject



13
14
15
# File 'lib/fir/lines.rb', line 13

def self.blank
  new([])
end

Instance Method Details

#==(other) ⇒ Object



45
46
47
# File 'lib/fir/lines.rb', line 45

def ==(other)
  other.members == members
end

#[](key) ⇒ Object



29
30
31
# File 'lib/fir/lines.rb', line 29

def [](key)
  @members[key].clone
end

#[]=(key, value) ⇒ Object



33
34
35
# File 'lib/fir/lines.rb', line 33

def []=(key, value)
  @members[key] = value
end

#add(n) ⇒ Object



49
50
51
# File 'lib/fir/lines.rb', line 49

def add(n)
  self.class.new(*(@members + [n]))
end

#blank?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/fir/lines.rb', line 17

def blank?
  @members == [[]]
end

#cloneObject



21
22
23
# File 'lib/fir/lines.rb', line 21

def clone
  self.class.new(*@members.clone.map(&:clone))
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/fir/lines.rb', line 25

def each(&block)
  @members.each(&block)
end

#join(chr = nil) ⇒ Object



41
42
43
# File 'lib/fir/lines.rb', line 41

def join(chr = nil)
  map(&:join).join(chr)
end

#lengthObject



37
38
39
# File 'lib/fir/lines.rb', line 37

def length
  @members.length
end

#removeObject



53
54
55
# File 'lib/fir/lines.rb', line 53

def remove
  self.class.new(*(@members[0...-1]))
end