SlideShare a Scribd company logo
1 of 28
Removing Methods
 Ruby Method of the Month
  Kevin Munc => @muncman
Adding a Method

class String
  def ruby_rocks?
    true #dat
  end
end
Fancy New Method


"rails".ruby_rocks?
      => true
Remove It!
class String
  remove_method :ruby_rocks?
end
Remove It!
class String
  remove_method :ruby_rocks?
end
"rails".ruby_rocks?
NoMethodError: undefined method
`ruby_rocks?' for "rails":String
A Redefined Method

class Crb
  def to_s
    "Thanks Randall!"
  end
end
Redefinition in
        Action
columbusrb = Crb.new
Redefinition in
        Action
columbusrb = Crb.new

columbusrb.to_s
Redefinition in
        Action
columbusrb = Crb.new

columbusrb.to_s
=> "Thanks Randall!"
Redefinition Removal
class Crb
  remove_method :to_s
end
                        Note that we didn’t have
                        to get a new instance for
                        the removal to take
                        effect.
Redefinition Removal
class Crb
  remove_method :to_s
end

columbusrb.to_s
                        Note that we didn’t have
                        to get a new instance for
                        the removal to take
                        effect.
Redefinition Removal
class Crb
  remove_method :to_s
end

columbusrb.to_s
                          Note that we didn’t have
                          to get a new instance for
                          the removal to take
                          effect.

=> "#<Crb:0x101651538>"
Inherited Method
ror = “Ruby on Rails”
ror.to_s
=> "Ruby on Rails"


                        We get the to_s from Object.

                        Note that the removal takes
                        effect for instances already
                        declared.
Inherited Method
ror = “Ruby on Rails”
ror.to_s
=> "Ruby on Rails"
class String
  remove_method :to_s   We get the to_s from Object.


end                     Note that the removal takes
                        effect for instances already
                        declared.
Inherited Method
ror = “Ruby on Rails”
ror.to_s
=> "Ruby on Rails"
class String
  remove_method :to_s    We get the to_s from Object.


end                      Note that the removal takes
                         effect for instances already
                         declared.


ror.to_s
=> "#<String:0x101682b88>"
Removal Location
class Object
  remove_method :to_s
end


                        Defined in Kernel.

                        Object mixes in Kernel.
Removal Location
class Object
  remove_method :to_s
end

NameError: method `to_s' not
defined in Object       Defined in Kernel.

                        Object mixes in Kernel.
Put It All Back
           Starting from a clean slate, so String still has to_s, etc.




class Crb
  def to_s
    "Thanks Randall!"
  end
end
Undefine the
        Redefine       Different than removal!




class Crb
  undef_method :to_s
end
                       Interesting that the
                       default output of to_s
                       is present in the output.
Undefine the
        Redefine       Different than removal!




class Crb
  undef_method :to_s
end
                       Interesting that the
                       default output of to_s
                       is present in the output.

columbusrb.to_s
Undefine the
         Redefine          Different than removal!




class Crb
  undef_method :to_s
end
                           Interesting that the
                           default output of to_s
                           is present in the output.

columbusrb.to_s
NoMethodError: undefined method
`to_s' for #<Crb:0x101651538>
Definitely Undefined
class String
  undef_method :to_s
end
                       Note that the undef also applied
                       to subclasses of the type where
                       the undef happened.
Definitely Undefined
class String
  undef_method :to_s
end
                         Note that the undef also applied
                         to subclasses of the type where
                         the undef happened.

"rails".to_s
NoMethodError: undefined method
`to_s' for "rails":String
Defined Elsewhere
class Crb
  undef_method :object_id
end


                            The undef succeeds
                            because the method is
                            available to class Crb.
Defined Elsewhere
class Crb
  undef_method :object_id
end

columbusrb = Crb.new        The undef succeeds
                            because the method is

columbusrb.object_id        available to class Crb.



NoMethodError: undefined method
`object_id' for #<Crb:0x10166d7d8>
Method Removal
remove_method :symbol
 Removed from the specific type only.

 Ruby still searches up the hierarchy.

undef_method :symbol
 Prevents calls to the method regardless
 of the type’s hierarchy.

Both defined in the Module class.
Finer Points
  (pun intended)
You can call remove_method only
on a method actually defined
within the class itself.

You can call undef_method on a
method accessible from the
class (inherited or mixed in).
Questions?
                Photo Credits:
    http://www.flickr.com/photos/tomscott/4225623/
 http://www.flickr.com/photos/slayer23/2215384832/
http://www.flickr.com/photos/andreweason/268627274/
   http://www.flickr.com/photos/tomscott/28188883/
  http://www.flickr.com/photos/jonmikel/259535350/

More Related Content

Viewers also liked

Ruby's String Slicing (MOTM 2009.07)
Ruby's String Slicing (MOTM 2009.07)Ruby's String Slicing (MOTM 2009.07)
Ruby's String Slicing (MOTM 2009.07)Kevin Munc
 
Therapy throuw photography
Therapy throuw photographyTherapy throuw photography
Therapy throuw photographyalinefrisch
 
Google Automotive Report by 7thFloor
Google Automotive Report by 7thFloorGoogle Automotive Report by 7thFloor
Google Automotive Report by 7thFloorAndrea Genovese
 
Collaborate to Innovate: a new venture capital model
Collaborate to Innovate: a new venture capital modelCollaborate to Innovate: a new venture capital model
Collaborate to Innovate: a new venture capital modelAndrea Genovese
 
Body Talks....Le Voyage
Body Talks....Le Voyage  Body Talks....Le Voyage
Body Talks....Le Voyage alinefrisch
 
Editoria Viaggi Meridiani2
Editoria Viaggi Meridiani2Editoria Viaggi Meridiani2
Editoria Viaggi Meridiani2Andrea Genovese
 
7thFloor Business Magazine n. 12
7thFloor Business Magazine n. 127thFloor Business Magazine n. 12
7thFloor Business Magazine n. 12Andrea Genovese
 
Augusto Coppola Business Plan-innovation-lab
Augusto Coppola Business Plan-innovation-labAugusto Coppola Business Plan-innovation-lab
Augusto Coppola Business Plan-innovation-labAndrea Genovese
 
Tiny Frogs
Tiny FrogsTiny Frogs
Tiny FrogsSINGHA
 
Obama Social Media Marketing & Web Communication Strategy
Obama Social Media Marketing & Web Communication StrategyObama Social Media Marketing & Web Communication Strategy
Obama Social Media Marketing & Web Communication StrategyAndrea Genovese
 
Tiny Frogs
Tiny FrogsTiny Frogs
Tiny FrogsSINGHA
 

Viewers also liked (13)

Ruby's String Slicing (MOTM 2009.07)
Ruby's String Slicing (MOTM 2009.07)Ruby's String Slicing (MOTM 2009.07)
Ruby's String Slicing (MOTM 2009.07)
 
Therapy throuw photography
Therapy throuw photographyTherapy throuw photography
Therapy throuw photography
 
Google Automotive Report by 7thFloor
Google Automotive Report by 7thFloorGoogle Automotive Report by 7thFloor
Google Automotive Report by 7thFloor
 
Presenta 7thfloor
Presenta 7thfloorPresenta 7thfloor
Presenta 7thfloor
 
Collaborate to Innovate: a new venture capital model
Collaborate to Innovate: a new venture capital modelCollaborate to Innovate: a new venture capital model
Collaborate to Innovate: a new venture capital model
 
Body Talks....Le Voyage
Body Talks....Le Voyage  Body Talks....Le Voyage
Body Talks....Le Voyage
 
Editoria Viaggi Meridiani2
Editoria Viaggi Meridiani2Editoria Viaggi Meridiani2
Editoria Viaggi Meridiani2
 
Fcl Retail 07 7th Floor
Fcl Retail 07 7th FloorFcl Retail 07 7th Floor
Fcl Retail 07 7th Floor
 
7thFloor Business Magazine n. 12
7thFloor Business Magazine n. 127thFloor Business Magazine n. 12
7thFloor Business Magazine n. 12
 
Augusto Coppola Business Plan-innovation-lab
Augusto Coppola Business Plan-innovation-labAugusto Coppola Business Plan-innovation-lab
Augusto Coppola Business Plan-innovation-lab
 
Tiny Frogs
Tiny FrogsTiny Frogs
Tiny Frogs
 
Obama Social Media Marketing & Web Communication Strategy
Obama Social Media Marketing & Web Communication StrategyObama Social Media Marketing & Web Communication Strategy
Obama Social Media Marketing & Web Communication Strategy
 
Tiny Frogs
Tiny FrogsTiny Frogs
Tiny Frogs
 

Similar to Removing Methods (MOTM 2010.01)

The Dark Art of Rails Plugins (2008)
The Dark Art of Rails Plugins (2008)The Dark Art of Rails Plugins (2008)
The Dark Art of Rails Plugins (2008)lazyatom
 
Introduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection APIIntroduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection APINiranjan Sarade
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in RubyConFoo
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogrammingjoshbuddy
 
Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013rivierarb
 
Magic in ruby
Magic in rubyMagic in ruby
Magic in rubyDavid Lin
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Christopher Haupt
 
Rails for zombies_2_cheatsheets
Rails for zombies_2_cheatsheetsRails for zombies_2_cheatsheets
Rails for zombies_2_cheatsheetsedith890
 
Introduction to Ruby MagLev
Introduction to Ruby MagLevIntroduction to Ruby MagLev
Introduction to Ruby MagLevrengelbrecht
 
Forbidden Fruit: A Taste of Ruby's ParseTree
Forbidden Fruit: A Taste of Ruby's ParseTreeForbidden Fruit: A Taste of Ruby's ParseTree
Forbidden Fruit: A Taste of Ruby's ParseTreeerr
 
Ruby: Beyond the Basics
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the BasicsMichael Koby
 
Ruby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyRuby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyTushar Pal
 
Metaprogramming code-that-writes-code
Metaprogramming code-that-writes-codeMetaprogramming code-that-writes-code
Metaprogramming code-that-writes-codeorga shih
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# DevelopersCory Foy
 

Similar to Removing Methods (MOTM 2010.01) (20)

The Dark Art of Rails Plugins (2008)
The Dark Art of Rails Plugins (2008)The Dark Art of Rails Plugins (2008)
The Dark Art of Rails Plugins (2008)
 
How to write Ruby extensions with Crystal
How to write Ruby extensions with CrystalHow to write Ruby extensions with Crystal
How to write Ruby extensions with Crystal
 
Introduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection APIIntroduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection API
 
block
blockblock
block
 
Ruby objects
Ruby objectsRuby objects
Ruby objects
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Metaprogramming
MetaprogrammingMetaprogramming
Metaprogramming
 
Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013Ruby object model at the Ruby drink-up of Sophia, January 2013
Ruby object model at the Ruby drink-up of Sophia, January 2013
 
Magic in ruby
Magic in rubyMagic in ruby
Magic in ruby
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)
 
Rails for zombies_2_cheatsheets
Rails for zombies_2_cheatsheetsRails for zombies_2_cheatsheets
Rails for zombies_2_cheatsheets
 
Ruby introduction
Ruby introductionRuby introduction
Ruby introduction
 
Python advance
Python advancePython advance
Python advance
 
Introduction to Ruby MagLev
Introduction to Ruby MagLevIntroduction to Ruby MagLev
Introduction to Ruby MagLev
 
Why I choosed Ruby
Why I choosed RubyWhy I choosed Ruby
Why I choosed Ruby
 
Forbidden Fruit: A Taste of Ruby's ParseTree
Forbidden Fruit: A Taste of Ruby's ParseTreeForbidden Fruit: A Taste of Ruby's ParseTree
Forbidden Fruit: A Taste of Ruby's ParseTree
 
Ruby: Beyond the Basics
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the Basics
 
Ruby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for rubyRuby object model - Understanding of object play role for ruby
Ruby object model - Understanding of object play role for ruby
 
Metaprogramming code-that-writes-code
Metaprogramming code-that-writes-codeMetaprogramming code-that-writes-code
Metaprogramming code-that-writes-code
 
Ruby for C# Developers
Ruby for C# DevelopersRuby for C# Developers
Ruby for C# Developers
 

More from Kevin Munc

Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013Kevin Munc
 
NaN, Zero, & Infinities
NaN, Zero, & InfinitiesNaN, Zero, & Infinities
NaN, Zero, & InfinitiesKevin Munc
 
Basic Scheduling with setTimeout & setInterval
Basic Scheduling with setTimeout & setIntervalBasic Scheduling with setTimeout & setInterval
Basic Scheduling with setTimeout & setIntervalKevin Munc
 
Apples & Oranges? Adventures in Equality Comparison & one of the ‘Bad Parts’
Apples & Oranges? Adventures in Equality Comparison & one of the ‘Bad Parts’Apples & Oranges? Adventures in Equality Comparison & one of the ‘Bad Parts’
Apples & Oranges? Adventures in Equality Comparison & one of the ‘Bad Parts’Kevin Munc
 
Number Conversions (MOTM 2010.12)
Number Conversions (MOTM 2010.12)Number Conversions (MOTM 2010.12)
Number Conversions (MOTM 2010.12)Kevin Munc
 
Percent Literals (MOTM 2010.09)
Percent Literals (MOTM 2010.09)Percent Literals (MOTM 2010.09)
Percent Literals (MOTM 2010.09)Kevin Munc
 
cycle (MOTM 2010.07)
cycle (MOTM 2010.07)cycle (MOTM 2010.07)
cycle (MOTM 2010.07)Kevin Munc
 
empty?, nil?, blank?, & present? (MOTM 2010.05)
empty?, nil?, blank?, & present? (MOTM 2010.05)empty?, nil?, blank?, & present? (MOTM 2010.05)
empty?, nil?, blank?, & present? (MOTM 2010.05)Kevin Munc
 
Take & Drop (MOTM 2010.04)
Take & Drop (MOTM 2010.04)Take & Drop (MOTM 2010.04)
Take & Drop (MOTM 2010.04)Kevin Munc
 
Helpers (MOTM 2010.03)
Helpers (MOTM 2010.03)Helpers (MOTM 2010.03)
Helpers (MOTM 2010.03)Kevin Munc
 
Grouping (MOTM 2010.02)
Grouping (MOTM 2010.02)Grouping (MOTM 2010.02)
Grouping (MOTM 2010.02)Kevin Munc
 
gsub (MOTM 2009.09)
gsub (MOTM 2009.09)gsub (MOTM 2009.09)
gsub (MOTM 2009.09)Kevin Munc
 
The Methods Method and Its Friends (MOTM 2009.08)
The Methods Method and Its Friends (MOTM 2009.08)The Methods Method and Its Friends (MOTM 2009.08)
The Methods Method and Its Friends (MOTM 2009.08)Kevin Munc
 

More from Kevin Munc (14)

Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013Ci for i-os-codemash-01.2013
Ci for i-os-codemash-01.2013
 
NaN, Zero, & Infinities
NaN, Zero, & InfinitiesNaN, Zero, & Infinities
NaN, Zero, & Infinities
 
Basic Scheduling with setTimeout & setInterval
Basic Scheduling with setTimeout & setIntervalBasic Scheduling with setTimeout & setInterval
Basic Scheduling with setTimeout & setInterval
 
Shellwords
ShellwordsShellwords
Shellwords
 
Apples & Oranges? Adventures in Equality Comparison & one of the ‘Bad Parts’
Apples & Oranges? Adventures in Equality Comparison & one of the ‘Bad Parts’Apples & Oranges? Adventures in Equality Comparison & one of the ‘Bad Parts’
Apples & Oranges? Adventures in Equality Comparison & one of the ‘Bad Parts’
 
Number Conversions (MOTM 2010.12)
Number Conversions (MOTM 2010.12)Number Conversions (MOTM 2010.12)
Number Conversions (MOTM 2010.12)
 
Percent Literals (MOTM 2010.09)
Percent Literals (MOTM 2010.09)Percent Literals (MOTM 2010.09)
Percent Literals (MOTM 2010.09)
 
cycle (MOTM 2010.07)
cycle (MOTM 2010.07)cycle (MOTM 2010.07)
cycle (MOTM 2010.07)
 
empty?, nil?, blank?, & present? (MOTM 2010.05)
empty?, nil?, blank?, & present? (MOTM 2010.05)empty?, nil?, blank?, & present? (MOTM 2010.05)
empty?, nil?, blank?, & present? (MOTM 2010.05)
 
Take & Drop (MOTM 2010.04)
Take & Drop (MOTM 2010.04)Take & Drop (MOTM 2010.04)
Take & Drop (MOTM 2010.04)
 
Helpers (MOTM 2010.03)
Helpers (MOTM 2010.03)Helpers (MOTM 2010.03)
Helpers (MOTM 2010.03)
 
Grouping (MOTM 2010.02)
Grouping (MOTM 2010.02)Grouping (MOTM 2010.02)
Grouping (MOTM 2010.02)
 
gsub (MOTM 2009.09)
gsub (MOTM 2009.09)gsub (MOTM 2009.09)
gsub (MOTM 2009.09)
 
The Methods Method and Its Friends (MOTM 2009.08)
The Methods Method and Its Friends (MOTM 2009.08)The Methods Method and Its Friends (MOTM 2009.08)
The Methods Method and Its Friends (MOTM 2009.08)
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Removing Methods (MOTM 2010.01)

  • 1. Removing Methods Ruby Method of the Month Kevin Munc => @muncman
  • 2. Adding a Method class String def ruby_rocks? true #dat end end
  • 4. Remove It! class String remove_method :ruby_rocks? end
  • 5. Remove It! class String remove_method :ruby_rocks? end "rails".ruby_rocks? NoMethodError: undefined method `ruby_rocks?' for "rails":String
  • 6. A Redefined Method class Crb def to_s "Thanks Randall!" end end
  • 7. Redefinition in Action columbusrb = Crb.new
  • 8. Redefinition in Action columbusrb = Crb.new columbusrb.to_s
  • 9. Redefinition in Action columbusrb = Crb.new columbusrb.to_s => "Thanks Randall!"
  • 10. Redefinition Removal class Crb remove_method :to_s end Note that we didn’t have to get a new instance for the removal to take effect.
  • 11. Redefinition Removal class Crb remove_method :to_s end columbusrb.to_s Note that we didn’t have to get a new instance for the removal to take effect.
  • 12. Redefinition Removal class Crb remove_method :to_s end columbusrb.to_s Note that we didn’t have to get a new instance for the removal to take effect. => "#<Crb:0x101651538>"
  • 13. Inherited Method ror = “Ruby on Rails” ror.to_s => "Ruby on Rails" We get the to_s from Object. Note that the removal takes effect for instances already declared.
  • 14. Inherited Method ror = “Ruby on Rails” ror.to_s => "Ruby on Rails" class String remove_method :to_s We get the to_s from Object. end Note that the removal takes effect for instances already declared.
  • 15. Inherited Method ror = “Ruby on Rails” ror.to_s => "Ruby on Rails" class String remove_method :to_s We get the to_s from Object. end Note that the removal takes effect for instances already declared. ror.to_s => "#<String:0x101682b88>"
  • 16. Removal Location class Object remove_method :to_s end Defined in Kernel. Object mixes in Kernel.
  • 17. Removal Location class Object remove_method :to_s end NameError: method `to_s' not defined in Object Defined in Kernel. Object mixes in Kernel.
  • 18. Put It All Back Starting from a clean slate, so String still has to_s, etc. class Crb def to_s "Thanks Randall!" end end
  • 19. Undefine the Redefine Different than removal! class Crb undef_method :to_s end Interesting that the default output of to_s is present in the output.
  • 20. Undefine the Redefine Different than removal! class Crb undef_method :to_s end Interesting that the default output of to_s is present in the output. columbusrb.to_s
  • 21. Undefine the Redefine Different than removal! class Crb undef_method :to_s end Interesting that the default output of to_s is present in the output. columbusrb.to_s NoMethodError: undefined method `to_s' for #<Crb:0x101651538>
  • 22. Definitely Undefined class String undef_method :to_s end Note that the undef also applied to subclasses of the type where the undef happened.
  • 23. Definitely Undefined class String undef_method :to_s end Note that the undef also applied to subclasses of the type where the undef happened. "rails".to_s NoMethodError: undefined method `to_s' for "rails":String
  • 24. Defined Elsewhere class Crb undef_method :object_id end The undef succeeds because the method is available to class Crb.
  • 25. Defined Elsewhere class Crb undef_method :object_id end columbusrb = Crb.new The undef succeeds because the method is columbusrb.object_id available to class Crb. NoMethodError: undefined method `object_id' for #<Crb:0x10166d7d8>
  • 26. Method Removal remove_method :symbol Removed from the specific type only. Ruby still searches up the hierarchy. undef_method :symbol Prevents calls to the method regardless of the type’s hierarchy. Both defined in the Module class.
  • 27. Finer Points (pun intended) You can call remove_method only on a method actually defined within the class itself. You can call undef_method on a method accessible from the class (inherited or mixed in).
  • 28. Questions? Photo Credits: http://www.flickr.com/photos/tomscott/4225623/ http://www.flickr.com/photos/slayer23/2215384832/ http://www.flickr.com/photos/andreweason/268627274/ http://www.flickr.com/photos/tomscott/28188883/ http://www.flickr.com/photos/jonmikel/259535350/

Editor's Notes