Created
April 27, 2014 01:28
-
-
Save ryansobol/11335516 to your computer and use it in GitHub Desktop.
It's fun to dream what a literal syntax for Ruby's Set class might look like...
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
# generic literal of symbols | |
<:earth, :wind, :fire> | |
# => Set.new [:earth, :wind, :fire] | |
# %e literal of symbols without interpolation | |
%e<earth wind fire> | |
# => Set.new [:earth, :wind, :fire] | |
# %E literal of symbols with interpolation | |
element = :wind | |
%E<earth #{element} fire> | |
# => Set.new [:earth, :wind, :fire] | |
# generic literal of strings | |
<'earth', 'wind', 'fire'> | |
# => Set.new ['earth', 'wind', 'fire'] | |
# %t literal of strings with interpolation | |
%t<earth wind fire> | |
# => Set.new ['earth', 'wind', 'fire'] | |
# %T literal of strings with interpolation | |
element = 'wind' | |
%T<earth #{element} fire> | |
# => Set.new ['earth', 'wind', 'fire'] | |
# generic literal of arrays | |
<[1, 2], [2, 3]> | |
# => Set.new([1, 2]).merge([2, 3]) | |
# generic literal of hashes | |
<{a: 1, b: 2}, {b: 1, c: 2}> | |
# => Set.new({a: 1, b: 2}).merge({b: 1, c: 2}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment