Skip to content

@mikker /inject.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Creating random code strings with Array#inject
# (to learn inject I am...)
# Using inject to create random strings
def code(size)
chars = ("a".."z").to_a+(0..9).to_a
Array.new(size).inject("") { |str, n| str += chars[rand(chars.size)].to_s }
end
50.times { |i| puts code(i) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.