I’m new to ruby, and this might be an obvious question but I really have no idea what to search for on Google to actually find what I’m looking for.
I’m doing algorithmic problems (not really relevant), and it gives me a square matrix, and asks if it has circular symmetry. I solve it like this:
s = STDIN.readlines.map { |x| x.chomp }.join ''
puts %w[YES NO][s == s.reverse ? 0 : 1]
Is it possible to put all that in one line? The only reason I can’t is because I think I have to store the string and then explicitly compare it later. And it sources the string from STDIN so I can’t re-read it. Any elegant solutions? Thanks!
Object#taptakes a block, and passes the object to that block. Thus, should be able to rewrite that as:Although I agree with the commenter that this is only going to hurt readability.