Skip to content

Commit

Permalink
Override fixnum for DSL...more like english
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Wood committed Aug 27, 2014
1 parent 8c510ac commit fdc55c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ require 'rumba'

Roomba.new('/dev/tty.usbserial') do
safe_mode
forward meter(1)
forward 1.meter
rotate :left
rotate -90 # degrees

rotate :right
rotate 90
backward meter(1)
backward 1.meter

# access to any methods in the Roomba class here!
end
Expand Down
36 changes: 19 additions & 17 deletions lib/rumba/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,28 @@ def rotate(direction, speed: DEFAULT_SPEED)
halt
end

# MEASUREMENT HELPERS
# TODO: break these out into separate helpers file?
def inches(num)
25.4 * num
end
alias_method :inch, :inches

def feet(num)
inches(num) * 12
end
alias_method :foot, :feet

def meters(num)
num * 1000
end
alias_method :meter, :meters

# eh, why not?
alias_method :forwards, :forward
alias_method :backwards, :backward
alias_method :turn, :rotate
end
end

# MEASUREMENT HELPERS
class Fixnum
def inches
25.4 * self
end
alias_method :inch, :inches

def feet
self.inches * 12
end
alias_method :foot, :feet

def meters
self * 1000
end
alias_method :meter, :meters
end

0 comments on commit fdc55c5

Please sign in to comment.