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 7754017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:12:03+00:00 2026-06-01T12:12:03+00:00

I am trying to move some model code to a module. The original model

  • 0

I am trying to move some model code to a module.

The original model method:

I am trying to move some model code to a module.

The original model method:

class Book < ActiveRecord::Base
  def book_royalty(period='enddate', basis="Net receipts")
    #stuff
  end
end

So I add

include Calculation   

and move the method to a module:

module Calculation
  def book_royalty(period='enddate', basis="Net receipts")
    #stuff
  end
end

But now I’m getting

wrong number of arguments (2 for 0)

This is the error I also get if I make the method in the book.rb model a class method i.e. if I make the method name self.book_royalty(args).

Am I inadvertently making the methods moved to the module class methods? I’m using include in book.rb, not extend. How can I get the parent model to successfully include the module’s methods?

Edit

book_royalty is called in the Royaltystatement model.

book.rb:

attr_accessor :book_royalty

royaltystatement.rb:

def initialize_arrays
  @royalty  = []
  ...
end

def sum_at_book_level(contract)
  contract.books.where(:exclude_from_royalty_calc => false).each do |book| 
    book.book_royalty("enddate", basis)
    @royalty.push(book.book_royalty("enddate", basis))
    # etc
end
  • 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-01T12:12:05+00:00Added an answer on June 1, 2026 at 12:12 pm

    Explanation:

    Your module defines a method book_royalty that takes two arguments. Then, a couple of lines after the inclusion of that module you use class macro attr_accessor which defines two methods,

    def book_royalty
      @book_royalty
    end
    
    def book_royalty= val
      @book_royalty = val
    end
    

    This effectively overwrites your book_royalty from the module. Now it accepts no arguments. Hence the error

    wrong number of arguments (2 for 0)

    when trying to execute line

    book.book_royalty("enddate", basis)
    

    You don’t need attr_accessor or anything else in order to use a method from included module. It becomes available automatically.

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

Sidebar

Related Questions

I'm trying to move some reusable portions of code into a class. This is
I'm trying to move some code into some class files to clean up my
Trying to move some divs using hover, this is my markup: <div class=item dark-grey>
I am trying to move some custom drawing code from a view into a
I'm trying to move some old code from hand-made persistence to Hibernate. The issue
Actually I am trying to move some box alternatively with in another box. I
I'm trying to move some table storage in Azure from local storage to the
I'm trying to move some Excel-Data to MySQL, but having troubles with encoding. What
I'm trying to analyse some code here that's been designed using an MVP Approach.
I am trying to build some utility to create document model from a string

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.