[ create a new paste ] login | about

Link: http://codepad.org/ldJ08dOw    [ raw code | output | fork ]

Ruby, pasted on Dec 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module UsefulFeatures
  def class_name
    self.class.to_s
  end
end

class Person
  include UsefulFeatures
end

x = Person.new
p x.class_name

# if you want the method on Person too, you’ll
# have to extend
class Person
  extend UsefulFeatures
end
# could have done this, too: Person.extend UsefulFeatures
p Person.class_name


Output:
1
2
"Person"
"Class"


Create a new paste based on this one


Comments: