-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inner assignment conditional is a pretty bad example... #39
Comments
Nice, @jtmarmon, we can put that in one line exactly. My point here was to show that we can also use retval = if vals.any?
do_something(vals)
else
do_something_different
end rather than: if vals.any?
retval = do_something(vals)
else
retval = do_something_different
end But, for sure it's best your solution in one line. What about we put the one line solution and also this solution? What do you think? |
Well I think you could best refine the page to - rather than focusing on specific examples - showing the multitude of ways you can be "lispy" in ruby (as ruby is quite lisp inspired). Examples: retval = if vals.any?
do_something(vals)
else
do_something_different
end retval = case my_val
when "foo"
2
when "bar"
3
else
5
end retval = vals.any? ? do_something(vals) : do_something_different retval = foo unless bar etc. generally performing assignment on expressions that use first class operators. this was just a few off the top of my head. if you like the idea for the revision i'd be happy to PR it |
I liked the idea! I think the multitude of ways is nice! And we can have the one line and also those examples you did. Looking forward for your PR. Thanks! 👍 |
on it. any ideas for the title of the article? |
My idea at the beginning it was "inner assignment", because I would like to remove the assignment inside my conditional. Since, we are still working with assignments, conditionals and we're trying to do the same thing... Why not keep the title or something like "Conditional Assignments" ? |
yeah i like it |
👍 looking forward for your PR! |
Why would you ever do
over
I think the inner assignment conditional only makes sense when more logic needs to be performed inside the conditions
The text was updated successfully, but these errors were encountered: