Created
October 10, 2012 15:57
-
-
Save danielmorrison/3866520 to your computer and use it in GitHub Desktop.
unicode ruby tricks
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
# If you like this, you'll love: | |
# https://github.com/collectiveidea/unicode_math | |
# encoding: utf-8 | |
module Kernel | |
define_method "√" do |number| | |
Math.sqrt(number) | |
end | |
end | |
# Then call: | |
# √ 5 | |
class Numeric | |
define_method "²" do | |
self ** 2 | |
end | |
end | |
# Then call: | |
# 10.² | |
# less cool, but fun | |
module Kernel | |
define_method "½" do | |
0.5 | |
end | |
end | |
# Then call: | |
# 5 + ½ | |
module Kernel | |
define_method "∞" do | |
1.0/0.0 | |
end | |
end | |
# Then call: | |
# ∞ | |
# or do cool things like: | |
# (-∞..∞).cover? 10 | |
# (-∞..∞).cover? ∞ * ∞ | |
# (-∞..∞).cover? ∞ + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment