GithubHelp home page GithubHelp logo

Comments (8)

franzejr avatar franzejr commented on August 22, 2024

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.

jtmarmon avatar jtmarmon commented on August 22, 2024

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.

franzejr avatar franzejr commented on August 22, 2024

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.

jtmarmon avatar jtmarmon commented on August 22, 2024

on it. any ideas for the title of the article?

from best-ruby.

franzejr avatar franzejr commented on August 22, 2024

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.

jtmarmon avatar jtmarmon commented on August 22, 2024

yeah i like it

from best-ruby.

franzejr avatar franzejr commented on August 22, 2024

👍 looking forward for your PR!

from best-ruby.

jtmarmon avatar jtmarmon commented on August 22, 2024

#40

from best-ruby.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.