Class: CfSim::Point

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, x, y) ⇒ Point

Returns a new instance of Point.



4
5
6
7
# File 'lib/cf_sim/point.rb', line 4

def initialize(name, x, y)
  @name = name
  @x, @y = x, y
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#xObject (readonly)

Returns the value of attribute x.



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#==(other) ⇒ Object



9
10
11
# File 'lib/cf_sim/point.rb', line 9

def ==(other)
  eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/cf_sim/point.rb', line 13

def eql?(other)
  @x == other.x && @y == other.y
end

#hashObject



17
18
19
# File 'lib/cf_sim/point.rb', line 17

def hash
  @x + @y
end

#to_sObject



21
22
23
# File 'lib/cf_sim/point.rb', line 21

def to_s
  "#{name}(#{x}, #{y})"
end