extending hobo module / class

6 views
Skip to first unread message

adamski

unread,
May 22, 2009, 6:11:11 AM5/22/09
to Hobo Users
Hi all

I am trying to cleanly redefine the Hobo.find_by_search method, as we
redefined it a while ago and I need to make further modifications
now.
I have been trying different methods, but to be honest this is not an
area of Ruby with which I am that familiar - I'm fine with redefining
methods in built in classes like Array, String, but not sure how to
adhere to the structure of Hobo's modules.

Currently I have a module called HoboExtend in my lib folder where I
am redefining the Hobo class, with "alias hobo_find_by_search
find_by_search"

Any help much appreciated.
Thanks

adamski

unread,
May 22, 2009, 6:22:03 AM5/22/09
to Hobo Users
OK so alias was throwing an error - here is what I have now:

module HoboExtend
module Hobo
class << self
def find_by_search ...

Bryan Larsen

unread,
May 22, 2009, 11:27:42 AM5/22/09
to hobo...@googlegroups.com
Does it work if you remove the "HoboExtend" wrapper? By doing that
you are defining in a different namespace. This works if you do an
"include" or "extend" elsewhere to pull it into the proper class.

But with ruby's open classes, you can just do a

module Hobo
class << self
def find_by_search ...

or

def Hobo.find_by_search
...
end

cheers,
Bryan

adamski

unread,
May 22, 2009, 1:29:18 PM5/22/09
to Hobo Users
Thank you Brian - that looks like the solution, I was overcomplicating
it..
Cheers

On May 22, 4:27 pm, Bryan Larsen <bryan.lar...@gmail.com> wrote:
> Does it work if you remove the "HoboExtend" wrapper?  By doing that
> you are defining in a different namespace.   This works if you do an
> "include" or "extend" elsewhere to pull it into the proper class.
>
> But with ruby's open classes, you can just do a
>
> module Hobo
>   class << self
>     def find_by_search ...
>
> or
>
> def Hobo.find_by_search
>   ...
> end
>
> cheers,
> Bryan
>
Reply all
Reply to author
Forward
0 new messages