Skip to content

Instantly share code, notes, and snippets.

@TaylorBeeston
Created July 17, 2020 03:04
Show Gist options
  • Save TaylorBeeston/f23630c3389bf2855a42b8edc64681fa to your computer and use it in GitHub Desktop.
Save TaylorBeeston/f23630c3389bf2855a42b8edc64681fa to your computer and use it in GitHub Desktop.
# Below are some examples of what I love about Ruby
# Code that reads like English
10.times { print 'Hello' }
this_variable_is_true = true
print 'Something' if this_variable_is_true
# Metaprogramming
class Integer
def hundred
self * 100
end
def thousand
self * 1000
end
end
class Enumerator
def print(string)
loop do
puts string
self.next
end
end
end
puts 10.thousand # prints 10000
1.hundred.times.print 'Wow!' # prints 'Wow!' one hundred times
# Powerful standard library
puts [*(0..9)].permutation(3).to_a.length # prints the number of permutations of length 3 for 0-9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment