Created
September 19, 2014 21:27
-
-
Save ZeroPivot/7d387c3d00c6343fd4cc to your computer and use it in GitHub Desktop.
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
#lulzy example of using self | |
class Something | |
attr_accessor :lol | |
def Something.new(*args) #pendatic... OR self.new (factory classes) | |
o = self.allocate.tap{ |s| puts "\t\tallocate: #{s.inspect} - #{s==self} - tap class: #{s.class} - self class: #{self.class}"} # create a new object of this class | |
o.send(:initialize, *args) | |
o | |
end | |
def new(*args) #now we can create new Something objects | |
y=Something.new(*args) | |
end | |
def initialize(*args) | |
p " self_inner (when 'initializing' Something): #{self} with args: #{args}" | |
@lol=Random.rand | |
p @lol | |
end | |
end | |
p self | |
def ps | |
p self | |
end | |
ps | |
p self_before="self_before: #{self}" | |
s=Something.new("s=Something.new") #new ends up calling initialize | |
s_1=s.new("s_1=s.new").new("hue").new("hue").new("hue").new("hue") | |
p s_1==s.new.new.new.new.new.new.new.new.new.new.new.new.new | |
puts s_1 | |
p self_after="self_after: #{self}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment