Comments (8)
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?
from best-ruby.
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
from best-ruby.
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! 👍
from best-ruby.
on it. any ideas for the title of the article?
from best-ruby.
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" ?
from best-ruby.
yeah i like it
from best-ruby.
👍 looking forward for your PR!
from best-ruby.
from best-ruby.
Related Issues (16)
- Why not put together? HOT 2
- Add description for each trick HOT 6
- (head, *tail) HOT 6
- Add categories for tricks
- Fixnum#times HOT 2
- Suggests reduce vs inject, but they're the same method HOT 13
- Try for treating nil HOT 5
- best-ruby/idiomatic_ruby/each_vs_map.md HOT 5
- idiomatic_ruby/each_vs_map.md change users_ids HOT 1
- Suggestion for inject HOT 1
- Add more Best Practices
- Add more refactorings HOT 1
- Display all options list in README. HOT 2
- Domain expired HOT 1
- convert to Gitbook HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from best-ruby.