Does anyone know how to access a module namespace using a chained method?

EngineBlogPost == @blog.engine_blog_post
Engine::BlogPost == ???

Thanks!

On Jun 6, 3:34pm, frizbe1605 [email protected] wrote:

EngineBlogPost == @blog.engine_blog_post
Engine::BlogPost == ???

You might want to elaborate - to me at least your question makes no
sense.

Fred.

Okay, I’m chaining methods. I want access to my class. I can access
SomeClass with a method like some_class. Now with engines in Rails
3.1, I can use modules to break apart my codebase. So now, SomeClass
would be Engine::SomeClass. If I try to access Engine::SomeClass with
a similar style method like engine_some_class, it returns with
EngineSomeClass rather than Engine::SomeClass.

Any ideas on a chainable method for accessing this class now that it
has the additional module namespace?

Thanks,

Steve

On Jun 6, 1:35pm, Frederick C. [email protected]

On Jun 7, 3:16pm, frizbe1605 [email protected] wrote:

Okay, I’m chaining methods. I want access to my class. I can access
SomeClass with a method like some_class. Now with engines in Rails
3.1, I can use modules to break apart my codebase. So now, SomeClass
would beEngine::SomeClass. If I try to accessEngine::SomeClass with
a similar style method like engine_some_class, it returns with
EngineSomeClass rather thanEngine::SomeClass.

I think you are expecting magic where there is none. If your blog
model has belogns_to :blog_post, … then you’ll always do
Blog.first.blog_post, whether blog_post is a BlogPost,
Engine::BlogPost or some other class altogether

Fred

If I call Engine::BlogPost everything is gravy,

If I call BlogPost then I get…

uninitialized constant BlogPost

On Jun 8, 11:35am, Frederick C. [email protected]

On Tuesday, June 7, 2011 8:16:02 AM UTC-6, frizbe1605 wrote:

Okay, I’m chaining methods. I want access to my class.

Access your class as in: obj.class (or something else)?

I can access
SomeClass with a method like some_class.

Do you mean you can take a string “some_class” and call:

“some_class”.camelize.constantize => SomeClass

Or, are you talking about some weird #method_missing-based feature of
rails
that I don’t know about?

Now with engines in Rails
3.1, I can use modules to break apart my codebase.

Well, in general terms, with ruby you’ve always been able to “break
apart”
your codebase using modules…

So now, SomeClass
would be Engine::SomeClass. If I try to access Engine::SomeClass with
a similar style method like engine_some_class, it returns with
EngineSomeClass rather than Engine::SomeClass.

So, I think the real question is, what do you mean by “it” in “it
returns
with…”? What method are you calling?

If I had to guess, it looks to me like you’re not talking so much about
calling a method #engine_some_class so much as passing this as a value
(string or symbol) to some method. Am I on the right track?

Any ideas on a chainable method for accessing this class now that it
has the additional module namespace?

What do you mean by chainable here? Do you mean method chaining like:

obj.method_a.method_b.method_c(arg1, arg2).method_d

On Jun 6, 1:35 pm, Frederick C. [email protected]

You need more elaboration still. I, like Fred, am still having a hard
time
knowing what you’re getting at.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs