Created
October 4, 2010 09:43
-
-
Save thedarkone/609458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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