this post was submitted on 22 Nov 2023
278 points (98.9% liked)

196

16744 readers
1812 users here now

Be sure to follow the rule before you head out.

Rule: You must post before you leave.

^other^ ^rules^

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 14 points 1 year ago (6 children)

Ruby has a method for this :)

[1] pry(main)> vars = ["one", "two", nil, "three"]
=> ["one", "two", nil, "three"]
[2] pry(main)> vars.compact
=> ["one", "two", "three"]

In Ruby, 0 and "" is truthy, so this would be a little different than the Python interpretation. You could filter with #select, but you'd typically write your code around this instead.

[–] [email protected] 19 points 1 year ago (4 children)

In Ruby, 0 and "" is truthy,

What the fuck?

[–] diemartin 8 points 1 year ago

Lua is the same. Only false and nil are "falsey".

I remember I fixed a bug in a mod for Minetest that assumed 0 was false and caused an infinite loop.

load more comments (3 replies)
load more comments (4 replies)