How do I return a variable from a Ruby method? -
what's best way return value of 'hash' variable?
define_method :hash_count char_count = 0 while char_count < 25 hash = '' hash << 'x' char_count += 1 end end
you have define hash
outside loop. if it's inside keep resetting on every iteration.
define_method :hash_count char_count = 0 hash = '' while char_count < 25 hash << 'x' char_count += 1 end hash # returns hash method end
by way, don't have keep track of char_count
. check length of string:
define_method :hash_count hash = '' hash << 'x' while hash.length < 25 hash # returns hash method end
Comments
Post a Comment