16. #singleton_methods
1. module Crb 2. class Motm
def brigade def self.short
puts ‘This’ puts ‘is’
end end
end 3. motm = Motm.new end 4.
def motm.part_one
puts ‘Spinal’
end
17. #singleton_methods
1. module Crb 2. class Motm
def brigade def self.short
puts ‘This’ puts ‘is’
end end
end 3. motm = Motm.new end 4. class << motm
def motm.part_one include Crb
puts ‘Spinal’ def part_two
end puts ‘Tap’
end
end
Continuing quest to lower the bar and discuss beginner-level topics in bite-sized chunks.
irb
Used methods method to choose a new MOTM...
Too Many! Instance methods, not Class methods!
(The Method of Physick is the first textbook on medicine published in English)
Grep!
Array of method names you can call on the instance.
Sort!
Though not in that order...
Starting with this class...
Note 2 methods defined *at this level*.
Synonymous (more or less).
Array of accessible method names you can call.
With false!
Maybe show &#x2018;true&#x2019; result in irb here.
Subtraction instead of &#x2018;false&#x2019;!
Supposed to be synonymous, according to PickAxe...
(Ruby 1.8.6, at least.)
methods(false) acts like singleton_methods(false).
Don&#x2019;t delay too long - maybe for discussion at the bar later...
irb demonstration?
def motm.another_method
puts &#x2018;Another!&#x2019;
end
Note: didn&#x2019;t have to pass false to protected_methods since String has none.
Note: now have to pass false.
Don&#x2019;t rush this slide (LOTS!).
http://www.rubyist.net/~slagell/ruby/singletonmethods.html
&#x201C;A method given only to a single object is called a singleton method.&#x201D;
Don&#x2019;t rush this slide (LOTS!).
http://www.rubyist.net/~slagell/ruby/singletonmethods.html
&#x201C;A method given only to a single object is called a singleton method.&#x201D;
Don&#x2019;t rush this slide (LOTS!).
http://www.rubyist.net/~slagell/ruby/singletonmethods.html
&#x201C;A method given only to a single object is called a singleton method.&#x201D;
Don&#x2019;t rush this slide (LOTS!).
http://www.rubyist.net/~slagell/ruby/singletonmethods.html
&#x201C;A method given only to a single object is called a singleton method.&#x201D;
These methods are only on this *instance*.
http://osdir.com/ml/lang.ruby.core/2005-04/msg00006.html
File is a good class for testing this stuff.
singleton_methods(true) ~ &#x201C;singleton_and_inherited_methods&#x201D;
"singleton_methods(true)" means "singleton methods on this object or,
if the object is a Class, this object and its ancestral classes."
No methods on this *instance*.
Different than the other methods covered... (no array).