Skip to content

Instantly share code, notes, and snippets.

@ryansobol
Created April 27, 2014 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryansobol/11335516 to your computer and use it in GitHub Desktop.
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...
# 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