Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OOP Open/Closed principal in Ruby?

Tags:

ruby

Often heard about the Open/Closed principal that says a class should be Open for extension and Closed for modification. Sounds great at the abstract level.

But is there any real-world use-cased example applied in the Ruby OOP land?

like image 885
Autodidact Avatar asked Apr 13 '26 06:04

Autodidact


1 Answers

Ruby classes are all open. There is no closed class.

Example:

class String
  def foo
    puts "bar"
  end
end

'anything'.foo

#bar
like image 61
SwiftMango Avatar answered Apr 15 '26 00:04

SwiftMango



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!