Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#*(scalar) ⇒ Object



4
5
6
# File 'lib/hash_vector.rb', line 4

def *(scalar)
	{:x => self[:x] * scalar.to_f, :y => self[:y] * scalar.to_f}
end

#+(vector) ⇒ Object



7
8
9
10
# File 'lib/hash_vector.rb', line 7

def +(vector)
	return {:x => self[:x] + vector[:x], :y => self[:y] + vector[:y]} if vector.kind_of? Hash
	{:x => self[:x] + vector[0,0], :y => self[:y] + vector[1,0]}
end

#as_matrixObject



12
13
14
# File 'lib/hash_vector.rb', line 12

def as_matrix
	Matrix.columns([[self[:x], self[:y]]])
end