Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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