Class: Pair

Inherits:
Object
  • Object
show all
Defined in:
lib/static_ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(first, second) ⇒ Pair

Returns a new instance of Pair.



4
5
6
7
8
# File 'lib/static_ruby.rb', line 4

def initialize(first, second)
  @first = first
  @second = second
  @size = 2
end

Instance Attribute Details

#firstObject (readonly)

Returns the value of attribute first.



2
3
4
# File 'lib/static_ruby.rb', line 2

def first
  @first
end

#secondObject (readonly)

Returns the value of attribute second.



2
3
4
# File 'lib/static_ruby.rb', line 2

def second
  @second
end

#sizeObject (readonly)

Returns the value of attribute size.



2
3
4
# File 'lib/static_ruby.rb', line 2

def size
  @size
end

Instance Method Details

#!=(o) ⇒ Object



22
23
24
# File 'lib/static_ruby.rb', line 22

def !=(o)
  @first != o.first || @second != o.second
end

#==(o) ⇒ Object



18
19
20
# File 'lib/static_ruby.rb', line 18

def ==(o)
  @first == o.first && @second == o.second
end

#each(&block) ⇒ Object



26
27
28
29
# File 'lib/static_ruby.rb', line 26

def each(&block)
  block.call(@first)
  block.call(@second)
end

#to_aObject



10
11
12
# File 'lib/static_ruby.rb', line 10

def to_a
  [@first, @second]
end

#to_sObject



14
15
16
# File 'lib/static_ruby.rb', line 14

def to_s
  "Pair(#{@first} #{@second})"
end