Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8475519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:54:57+00:00 2026-06-10T17:54:57+00:00

I recently posted a question on stackoverflow where I did something to effect of

  • 0

I recently posted a question on stackoverflow where I did something to effect of

@period_registration.period.event

However, it was suggested that I do something like the following:

def event
  period.event
end

@period_registration.event

My general sense is that this seems a little heavy-handed. Looking at this previous posting How do I apply the Law of Demeter to this? shows how heavy handed this can become if you did this for every association.

How common of a practice is this in rails? My thought is that even if this is technically the right thing to do, if it isn’t a part of the rails culture then it seems that doing this will throw people off. And, more importantly, actually make the code less maintainable as other developers think you’re wasting your time with all these helper methods.

Let’s say I wanted to impliment this, would @period_registration.event.city, where city is an attribute of event, not a seperate object also violate LoD or would I need to write ANOTHER method so I could do: @period_registration.city

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:54:58+00:00Added an answer on June 10, 2026 at 5:54 pm

    To be honest, slavish adherence to the Law of Demeter is pretty rare. Still, for associations, this is such a common pattern that it has a shortcut that removes most of the hard work from you:

    class PeriodRegistration < ActiveRecord::Base
      belongs_to :period
      delegate :event, :to => :period
    end
    
    PeriodRegistration.new.event # calls PeriodRegistration.new.period.event
    

    You can read more about this at the Module#delegate documentation.

    At the risk of sounding excessively self-promoting, I have a blog post that discusses this and other ways to try to respect the Law of Demeter, if that’s your thing. Check it out if you’re curious to learn more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently posted this question about codes for a gift-card-like voucher that users can
From another question I recently posted, it seems that Classic ASP might not be
Relatively new to python. I recently posted a question in regards to validating that
As suggested in a macro-related question I recently posted to SO , I coded
I've recently posted a general question about RAII at SO . However, I still
I recently posted a question on stackoverflow about the less popular js function document.captureEvents()
I recently posted a question about a WCF Restful web service that I am
In another question I posted recently I was suggested to use a java.util.Timer in
I recently posted a question on StackOverflow: SOAP message deserialization issue in WCF -
Recently I posted a question on Highcharts column charts drilldown. I have found that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.