Boolean comparison of array of strings in Ruby
Posted
by Kyle Kaitan
on Stack Overflow
See other posts from Stack Overflow
or by Kyle Kaitan
Published on 2009-11-20T04:17:47Z
Indexed on
2010/06/02
12:44 UTC
Read the original article
Hit count: 212
ruby
I've got an array in Ruby that essentially represents a square boolean matrix. Dots represent zeroes, while any other character represents ones. Example:
irb(main):044:0> g
=> [".b", "m."] # This grid has two '1' values and two '0' values.
I'd like to perform a specified logical operation (say, OR) on this array with another similar array to get a third result. For example, if h is ["q.", "r."], then something akin to g.perform_or(h) should yield a new array ["qb", "r."]. (The choice of r to represent the result of 'm' || 'r' is arbitrary and not relevant; any other non-'.' character can be there.)
How might I do this?
Edit: I made an error in my example. Apologies!
© Stack Overflow or respective owner