Skip to content

Instantly share code, notes, and snippets.

@thedarkone
Created October 4, 2010 09:43
Show Gist options
  • Save thedarkone/609458 to your computer and use it in GitHub Desktop.
Save thedarkone/609458 to your computer and use it in GitHub Desktop.
module Trigo
[:sin, :cos, :tan].each do |trigo_fun|
class_eval <<-RUBY_EVAL, __FILE__, __LINE__
def #{trigo_fun}(angle)
_trigo(:#{trigo_fun}, angle)
end
RUBY_EVAL
end
private
def _trigo(fun_name, angle)
assert_type angle, :Number
Number.new(Math.send(fun_name, _to_radius(angle.value)), angle.numerator_units)
end
FULL_CIRCLE = 360.0
def _to_radius(value)
Math::PI * (value / FULL_CIRCLE)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment