Skip to content

Instantly share code, notes, and snippets.

@ZeroPivot
Created September 19, 2014 21: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 ZeroPivot/7d387c3d00c6343fd4cc to your computer and use it in GitHub Desktop.
Save ZeroPivot/7d387c3d00c6343fd4cc to your computer and use it in GitHub Desktop.
#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