refactoring

Discussion in 'Ruby' started by barjunk, May 26, 2007.

  1. barjunk

    barjunk Guest

    Although this particular code is part of some goofing around I am
    doing in with Rails, I have what I think is some specific ruby
    questions. If I should take this to the rails list, please let me
    know.

    Alos, I am referencing pastie...if there is a better way for me to
    have done this, that would be good to know as well.

    So the main code is here: http://pastie.caboo.se/64700

    So as you can see it is fairly straight forward. It seems to me that
    it needs some refactoring.

    This is where the problem comes in.

    I'm fairly new to ruby and am hoping for some suggestions on how to
    refactor this code.

    My initial thought was to add another class called Role. Except I'm
    not really sure what steps to take to make that happen.

    I'm most interested in the thinking behind this process. You
    experienced guys seem to just know the answers, but I'd like to know
    what led you to whatever decision you made.

    Maybe I'm not even asking the right questions here...but I know it
    will be an adventure.

    Thanks for any insight.

    Mike B.
     
    barjunk, May 26, 2007
    #1
    1. Advertising

  2. barjunk

    barjunk Guest

    On May 25, 3:27 pm, barjunk <> wrote:
    > Although this particular code is part of some goofing around I am
    > doing in with Rails, I have what I think is some specific ruby
    > questions. If I should take this to the rails list, please let me
    > know.
    >
    > Alos, I am referencing pastie...if there is a better way for me to
    > have done this, that would be good to know as well.
    >
    > So the main code is here:http://pastie.caboo.se/64700
    >
    > So as you can see it is fairly straight forward. It seems to me that
    > it needs some refactoring.
    >
    > This is where the problem comes in.
    >
    > I'm fairly new to ruby and am hoping for some suggestions on how to
    > refactor this code.
    >
    > My initial thought was to add another class called Role. Except I'm
    > not really sure what steps to take to make that happen.
    >
    > I'm most interested in the thinking behind this process. You
    > experienced guys seem to just know the answers, but I'd like to know
    > what led you to whatever decision you made.
    >
    > Maybe I'm not even asking the right questions here...but I know it
    > will be an adventure.
    >
    > Thanks for any insight.
    >
    > Mike B.



    One other thing...the Myuser model does not have a row associated with
    it. These records will come from a non-database source.

    Mike B.
     
    barjunk, May 26, 2007
    #2
    1. Advertising

  3. Mike,

    There's a Rails-Talk list for Ruby on Rails questions. You may find
    that helpful for Rails-specific tips on structuring your
    controllers. See http://groups.google.com/group/rubyonrails-talk.

    Feel free to give me an email off-list or send an email to that list
    for the Rails-specific stuff. A few tips for now:
    - If Myuser isn't coming from the database, you probably don't
    want to inherit from ActiveRecord
    - I wouldn't expect your index method to work as written - you'll
    probably end up with double render errors
    --- which leads me to suggest that your first step may be to get
    familiar with Test::Unit or Rspec so you can easily test your code,
    which will help you refactor with confidence. If you need help
    getting started with either of these, let me know.

    Here's a general Ruby tip for you, though:

    Instead of this:

    @myuser = session[:user] ? session[:user] : Myuser.new

    you can accomplish the same with this:

    @myuser = session[:user] || Myuser.new

    Both forms are fine, IMO, but the second is more idiomatic Ruby.

    Hope this helps, and good luck getting started!

    David


    On May 25, 2007, at 6:35 PM, barjunk wrote:

    > On May 25, 3:27 pm, barjunk <> wrote:
    >> Although this particular code is part of some goofing around I am
    >> doing in with Rails, I have what I think is some specific ruby
    >> questions. If I should take this to the rails list, please let me
    >> know.
    >>
    >> Alos, I am referencing pastie...if there is a better way for me to
    >> have done this, that would be good to know as well.
    >>
    >> So the main code is here:http://pastie.caboo.se/64700
    >>
    >> So as you can see it is fairly straight forward. It seems to me that
    >> it needs some refactoring.
    >>
    >> This is where the problem comes in.
    >>
    >> I'm fairly new to ruby and am hoping for some suggestions on how to
    >> refactor this code.
    >>
    >> My initial thought was to add another class called Role. Except I'm
    >> not really sure what steps to take to make that happen.
    >>
    >> I'm most interested in the thinking behind this process. You
    >> experienced guys seem to just know the answers, but I'd like to know
    >> what led you to whatever decision you made.
    >>
    >> Maybe I'm not even asking the right questions here...but I know it
    >> will be an adventure.
    >>
    >> Thanks for any insight.
    >>
    >> Mike B.

    >
    >
    > One other thing...the Myuser model does not have a row associated with
    > it. These records will come from a non-database source.
    >
    > Mike B.
    >
    >
     
    David L Altenburg, May 26, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Refactorit

    come learn all about refactoring

    Refactorit, Feb 22, 2004, in forum: Java
    Replies:
    0
    Views:
    347
    Refactorit
    Feb 22, 2004
  2. Sebastian Jekutsch

    Survey on refactoring activities using IDEs

    Sebastian Jekutsch, Jun 8, 2004, in forum: Java
    Replies:
    5
    Views:
    479
  3. Christian Bongiorno

    Odd Multi-thread behavior when refactoring

    Christian Bongiorno, Jun 21, 2004, in forum: Java
    Replies:
    1
    Views:
    395
    Thomas Weidenfeller
    Jun 22, 2004
  4. Anan H. Samiti
    Replies:
    33
    Views:
    5,539
    Roedy Green
    Jul 30, 2004
  5. -
    Replies:
    6
    Views:
    629
    Wibble
    May 14, 2005
Loading...

Share This Page