-
-
Save andrewbredow/3866712 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
# 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