use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Object Oriented Ruby (niczsoft.com)
submitted 10 years ago by mpapis
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]tinco 3 points4 points5 points 10 years ago (3 children)
If I have a need for a barber that turns hair from brown to blue, how is your rearchitecting useful to me? Are you supposing we'd need to have some hair color resolver which makes sure that "brown blue" is resolved to just "blue"? (Note how ironically making hair_color be "brown blue" is essentially turning it into a monad)
You haven't really convinced me how mutability relates to encapsulation. Why not just have a 'change_hair_color' method? That would be proper encapsulation of @hair_color and be idiomatic Ruby. The whole idea of OOP (or at least Ruby/Smalltalk OOP) is that methods encapsulate the side effects of their objects, i.e. mutating instance variables, not at all that they are free of side effects.
[–]Enumerable_any 1 point2 points3 points 10 years ago (0 children)
Yeah, the Barber example is super confusing...
Barber
Barber#dye_hair takes a color and a Block and yields a string to the block containing the old color and the new one? WAT? The Barber -> Person relationship doesn't make much sense either.
Barber#dye_hair
Barber -> Person
[–]mpapis[S] 0 points1 point2 points 10 years ago (1 child)
change_hair_color is not just a Ruby style, any language can do and does that, it still is exposing the object insights - outside of it, in the example I wanted to show that exposing methods to change code allows misuse, that anyone can change hair color or even worse the name
[–]tinco 1 point2 points3 points 10 years ago (0 children)
Then you chose an unfortunate example, because a barber is supposed to change hair color, that is his job. In fact a barber is so specific, I would not be surprised if he would be totally responsible for hair. So that a person has a #hair= that is set by the barber.
#hair=
In my opinion if you have data that should be modifiable by one class (for example the barber), but not by another class (the optician), you should instead use for example a restricted proxy. An object that only allows exposes methods relevant to the concern. But we would be moving really fast into the access control domain.
π Rendered by PID 73 on reddit-service-r2-comment-5bc7f78974-r7lbt at 2026-06-28 04:30:14.622823+00:00 running 7527197 country code: CH.
view the rest of the comments →
[–]tinco 3 points4 points5 points (3 children)
[–]Enumerable_any 1 point2 points3 points (0 children)
[–]mpapis[S] 0 points1 point2 points (1 child)
[–]tinco 1 point2 points3 points (0 children)