Skip to content

Instantly share code, notes, and snippets.

@andrewbredow
Forked from danielmorrison/gist:3866520
Created October 10, 2012 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewbredow/3866712 to your computer and use it in GitHub Desktop.
Save andrewbredow/3866712 to your computer and use it in GitHub Desktop.
unicode ruby tricks
# 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
module Kernel
define_method "ಠ_ಠ" do |message|
raise Exception, message
end
end
# Then call:
# ಠ_ಠ "I am disappoint"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment