Last active
August 29, 2015 14:08
-
-
Save gmodarelli/4c2804d72be07263b02d to your computer and use it in GitHub Desktop.
Source Code Reading
This file contains 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
define_method(abbr) { |date = nil| DatePart.new(abbr, date) } |
This file contains 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
names = [ 'Giuseppe', 'Giulia', 'Luca', 'Andrea', 'Roberto' ] | |
grouped_by_first_letter = names.group_by { |name| name[0] } | |
puts grouped_by_first_letter | |
# >> {"G"=>["Giuseppe", "Giulia"], "L"=>["Luca"], "A"=>["Andrea"], "R"=>["Roberto"]} |
This file contains 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
module MyModule | |
chars = %w(A B C) | |
words = chars.permutation.to_a | |
words.each do |word| | |
method_name = word.join | |
module_eval(<<-PERMUTATION, __FILE__, __LINE__) | |
def #{method_name} | |
puts "#{word}" | |
end | |
PERMUTATION | |
end | |
end | |
include MyModule | |
abc # => nil | |
# >> a | |
# >> b | |
# >> c |
This file contains 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
chars = %w(A B C) | |
words = chars.permutation.to_a | |
# => [["A", "B", "C"], | |
# ["A", "C", "B"], | |
# ["B", "A", "C"], | |
# ["B", "C", "A"], | |
# ["C", "A", "B"], | |
# ["C", "B", "A"]] |
This file contains 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
chars = %w(A B C) | |
words = chars.permutation(2).to_a | |
# => [["A", "B"], ["A", "C"], ["B", "A"], ["B", "C"], ["C", "A"], ["C", "B"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment