:to argument to match() -- how is it converted to class/method name

19 views
Skip to first unread message

Brian Sammon

unread,
Oct 27, 2014, 3:25:17 PM10/27/14
to rubyonra...@googlegroups.com
Is there any documentation for how the match command converts the ":to"
argument to a class and method name?

If I have
match '<path>', to: '<sort-of-a-class-name>#<sort-of-a-method-name>',
via: :get
How does it go from <sort-of-a-class-name> to <actual-class-name>, and
more importantly, how do I go in the reverse direction?

I can probably figure this out via trial-and-error, but I'd like to see
docs if there are some, or contribute some docs if not.

Andy Ogzewalla

unread,
Oct 28, 2014, 7:50:35 AM10/28/14
to rubyonra...@googlegroups.com, rubyonra...@brisammon.fastmail.fm
This is not really documented anywhere, and tracing through the source is difficult. Within Rails the string inflector methods #classify and #underscore are used to go between snake-case names and camel-cased class and module names.


    "MyFoo".underscore          # => "my_foo"
    "MyApp::Foo".underscore  # => "my_app/foo"


    "my_foo".classify         # => "MyFoo"
    "my_app/foo".classify  # => "MyApp::Foo"
Reply all
Reply to author
Forward
0 new messages