[Ruby] When you want to assign the result obtained by conditional branching to a variable and put it in the argument

Before

    if planner_admins.any? {|planner_admin| planner_admin.ad?}
      admins = [Admin.get_invoice_viewer]
    else
      admins = planner_admins
    end
    SlackNoticeService.notice_invoice_viewer(@confirm, sponsor, admins)

After


    admins = if planner_admins.any? {|planner_admin| planner_admin.ad?}
               [Admin.get_invoice_viewer]
             else
               planner_admins
             end
    SlackNoticeService.notice_invoice_viewer(@confirm, sponsor, admins)

Recommended Posts

[Ruby] When you want to assign the result obtained by conditional branching to a variable and put it in the argument
[Ruby] I want to put an array in a variable. I want to convert to an array
A memorandum when you want to see the data acquired by Jena & SPARQL for each variable.
Be absolutely careful when putting the result of and / or in a variable!
When reassigning to an argument in a Ruby method and then calling `super` → The reassigned one is used
[ruby] How to assign a value to a hash by referring to the value and key of another hash
Assign a Java8 lambda expression to a variable and reuse it
Use JLine when you want to handle keystrokes on the console character by character in Java
If you want to mock a method in RSpec, you should use the allow method for mock and the singleton method.
[RSpec] When you want to use the instance variable of the controller in the test [assigns is not recommended]
I want to download a file on the Internet using Ruby and save it locally (with caution)
A memo when you want to clear the time part of the calendar
Is it possible to put the library (aar) in the Android library (aar) and use it?
Notation to put a variable in a string
If it is Ruby, it is efficient to make it a method and stock the processing.
How to convert a value of a different type and assign it to another variable
Conditional branching of the result of SQL statement to search only one in Java
When you want to bind InputStream in JDBI3
A note when you want Tuple in Java
When you want to use the method outside
[Ruby] When you want to replace multiple characters
I want to get the value in Ruby
Summary of copy and paste commands used when you want to delete the cache in iOS application development anyway
I want you to put the story that the error was solved when you stabbed the charger in the corner of your head
I want to find the MD5 checksum of a file in Java and get the result as a string in hexadecimal notation.
If you want to know the options when configuring Ruby, see `RbConfig :: CONFIG ["configure_args "]`
Until you create a Spring Boot project in Intellij and push it to Github
[Ruby] How to use standard output in conditional branching
When you want to dynamically replace Annotation in Java8
If you want to recreate the instance in cloud9
[Ruby + Rails] When you want to register in Mailchimp's mail list together with user registration
[Ruby] Get in the habit of using the dup method when making a copy of a string variable
When you want to change the wording to be displayed when making a select box from enum
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
Until you build a project described in scala with Maven and execute it with the scala command.
Click the [rails] button to create a random alphanumeric password and enter it in the password field
When you want to reflect the Master Branch information in the Current Branch you are currently working on
I want to call a method and count the number
When you want to explicitly write OR or AND with ransack
I want to create a Parquet file even in Ruby
When you want to change the MySQL password of docker-compose
I want to simplify the conditional if-else statement in Java
How to write when you want to keep line breaks and output while avoiding XSS in Rails
Object-oriented design that can be used when you want to return a response in form format
[For super beginners] The minimum knowledge you want to keep in mind with hashes and symbols
What to do when you want to know the source position where the method is defined in binding.pry
When you want to check whether the contents of a property can be converted to a specific type
A trick when you want to insert a lot of line breaks and tabs when substituting a character string
[Output] Learn Ruby from what you want to do at the fastest speed-Part 2 "Create a flowchart"
An example of a small work when you want to divide the definition value according to the environment but do not want to be aware of it
When installing a gem with C extension in Ruby, I want to finish it quickly using multiple CPU cores like make -j4
I want to import the pull-down menu items when submitting a form in Rails into CSV and display them from the DB data.
A story that could be implemented neatly by using polymorphism when you want to express two types of data in one table