Skip to content

Instantly share code, notes, and snippets.

@danielmorrison
Created October 10, 2012 15:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielmorrison/3866520 to your computer and use it in GitHub Desktop.
Save danielmorrison/3866520 to your computer and use it in GitHub Desktop.
unicode ruby tricks
# 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