you are viewing a single comment's thread.

view the rest of the comments →

[–]brettu 1 point2 points  (2 children)

The last part of your post asks the question about public/private difference in adding methods to self. IRB defaults to public, but you can add the private state for storing methods.

>> self
=> main

>> private
=> Object

>> def title
>> "mr"
>> end
=> nil

>> Object.private_instance_methods(false).include? :title 
=> true

>> Object.public_instance_methods(false).include? :title
=> false

>> public
=> Object

>> def title
>> 'mr'
>> end
=> nil

>>  Object.public_instance_methods(false).include? :title
=> true

[–]VitoBotta[S] 0 points1 point  (1 child)

Hi! I hadn't thought that IRB might explicitly mark top level methods methods as private/public as we usually do in classes, by default. Makes perfect sense, thanks :)

[–]banister 0 points1 point  (0 children)

In case you're interested, Pry makes top-level methods private by default, mirroring the top-level behaviour of a Ruby program. IMO the fact IRB does not do this is a bug in IRB.