Skip to content

How to use a condition in Squib with If or Case? #354

Answered by andymeneely
LouisDeconinck asked this question in Q&A
Discussion options

You must be logged in to vote

There's always a way!

Ruby's nil has the to_s method and it returns '', so I would do "images/#{t.to_s.downcase}1.png"

Ruby also has the &. operator as well. So t&.downcase would return nil if t was nil. https://ruby-doc.org/core-2.6/doc/syntax/calling_methods_rdoc.html

Either of those options along with the new placeholder option to png would be good.

You can do if-statements inside of map. So things like

data.effect1.map do |e|
  if something
    foo
  else 
    bar
end

Uglier option is the ternary operator... so like data.effect1.map { |e| e.something ? foo : bar }

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
3 replies
@LouisDeconinck
Comment options

@LouisDeconinck
Comment options

@andymeneely
Comment options

Comment options

You must be logged in to vote
3 replies
@LouisDeconinck
Comment options

@LouisDeconinck
Comment options

@LouisDeconinck
Comment options

Answer selected by LouisDeconinck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants