Created
August 12, 2015 22:06
-
-
Save ksss/e2f31e8743540c3009a1 to your computer and use it in GitHub Desktop.
File scope method
This file contains hidden or 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
class OpenClass | |
module InternalMethods | |
refine OpenClass do | |
def foo | |
:foo | |
end | |
end | |
end | |
using InternalMethods | |
def bar | |
foo | |
end | |
end | |
p OpenClass.new.bar | |
module InternalMethods | |
refine Object do | |
def one | |
1 | |
end | |
end | |
end | |
using InternalMethods | |
p one |
This file contains hidden or 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
#! /usr/bin/env ruby | |
require './lib' | |
class OpenClass | |
def baz | |
foo | |
end | |
end | |
OpenClass.new.baz rescue puts "error: OpenClass#baz cannot call" | |
one rescue puts "error: `one' cannot call" | |
# $ ruby main.rb | |
# :foo | |
# 1 | |
# error: OpenClass#baz cannot call | |
# error: `one' cannot call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment