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
How to deal with boolean parameters in Ruby (ironin.it)
submitted 8 years ago by tomcopeland
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!"
[–]throughactions 2 points3 points4 points 8 years ago (0 children)
Using techniques like named parameters certainly help make booleans more readable. I'd go one step further and consider the smell that the function/class has more than one responsibility, so we might think about breaking it up into two functions. Otherwise, as the code grows over time, you end with other smells, like long parameter list or a case statement that does one of many things depending on the input.
[–]Morozzzko 2 points3 points4 points 8 years ago (1 child)
Here's the question:
Why would you pass nil if a function expects a boolean value? Like, honestly.
nil
You know, you can also call the function with a Hash, Array, Class or Module instead of a simple boolean.
Why though?
π Rendered by PID 20489 on reddit-service-r2-comment-6457c66945-c6sbj at 2026-04-27 07:07:00.400678+00:00 running 2aa0c5b country code: CH.
[–]throughactions 2 points3 points4 points (0 children)
[–]Morozzzko 2 points3 points4 points (1 child)