Created
July 17, 2020 03:04
-
-
Save TaylorBeeston/f23630c3389bf2855a42b8edc64681fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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