Created
September 20, 2012 12:08
-
-
Save sumanmukherjee03/3755516 to your computer and use it in GitHub Desktop.
Messing with bindings in ruby
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
# Coding hazard. | |
class CoOrdinate | |
attr_reader :x, :y | |
def initialize(x, y) | |
@x = x | |
@y = y | |
end | |
end | |
class InverseCoOrdinate < CoOrdinate | |
def initialize(x, y) | |
@x = y | |
@y = x | |
end | |
end | |
class JediCoOrdinate < InverseCoOrdinate | |
def initialize(x, y, invert = true) | |
invert ? super(x, y) : draw_light_saber(x, y) | |
end | |
def self.grandparent | |
self.superclass.superclass | |
end | |
private | |
def draw_light_saber(x, y) | |
super_init = self.class.grandparent.instance_method(:initialize).send(:bind, self) | |
super_init.call(x,y) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment