I hear "Ruby is pure OOP language" and "everything in Ruby is an object." If it is so, why do we have these two situations?
puts and print work on a string object. According to OOP rules, the object's method is the one that should manipulate it's state.Can anyone explain how these two situations fit with the phrase "Ruby is pure OOP language"?
puts and print do not do anything to the arguments (which are not necessarily strings by the way). They modify the IO streams, and that is where these methods are defined (although syntax sugar in Kernel makes them accessible from almost anywhere).
When there is no explicit class body, the code is interpreted in the context of main object, which belongs to the Object class.
puts() is a method in the IO class. See http://www.ruby-doc.org/core-2.1.3/IO.html#method-i-puts
IRB is a module, so it's an Object too. See http://ruby-doc.com/docs/ProgrammingRuby/html/irb.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With