Skip to content

Instantly share code, notes, and snippets.

@focusaurus
Created June 18, 2015 01:46
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 focusaurus/b7f59b029f66e6b661cf to your computer and use it in GitHub Desktop.
Save focusaurus/b7f59b029f66e6b661cf to your computer and use it in GitHub Desktop.
Review: Metaprogramming in ES6: Symbols and why they're awesome
class BoringClass  
end  
class CoolClass  
  def ==(other_object)
   other_object.is_a? MyClass
  end
end  
BoringClass.new == BoringClass.new #=> false  
CoolClass.new == CoolClass.new #=> true!  
  • Seems like that MyClass should be CoolClass
  • I always prefer realistic examples

Symbol('foo') !== Symbol('foo'); // true!

I'd rather see that as

Symbol('foo') === Symbol('foo'); // false!

Near the beginning of the material about symbols, I could use a numbered list of use cases driving the addition of symbols. Eventually it's clear after reading the lengthy descriptions of what the do, what they don't do, and how they integrate for operator overloading type scenarios, but at the beginning I didn't have a good set of mental boxes to be filled so the information just piles up disorganized in my short-term memory.

The back story on Symbol.unscopables is good context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment