zetachang / react.rb

Opal Ruby wrapper of React.js library.
http://reactrb.org/
MIT License
547 stars 35 forks source link

Allow component Foo to be invoked without parens or a block #115

Closed catmando closed 8 years ago

catmando commented 8 years ago

Currently you have to say Foo() or Foo {} so ruby can determine Foo is a method.

A recent SO question got me thinking about this http://stackoverflow.com/questions/34657494/why-does-a-method-call-need-to-be-disambiguated-when-it-can-in-principle-be-a-co/34659428#34659428

I see no reason why we should not update const_missing so that if the missing "const" is in fact a subclass of React::Component::Base (or has the mixin) then we go ahead and make the method call.

While it would require we open class Module, it would only effect the behavior of React Component classes, it would get rid of an exception that constantly confuses beginners, and make the code more readable.

ajjahn commented 8 years ago

@catmando Can't we raise a const missing exception if the method doesn't exist either, replicating as much standard ruby behavior as possible?

catmando commented 8 years ago

@ajjahn - if you mean in the case that you say Foo but there is no component Foo, then yes, I would say we just use call the original std lib method.

catmando commented 8 years ago

This is not going to work... what was I thinking Foo is defined as a constant so of course const_missing would never be raised.

sollycatprint commented 8 years ago

This issue was moved to reactrb/reactrb#115