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

  • SEARCH
  • Home
  • 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 7760593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:55:51+00:00 2026-06-01T13:55:51+00:00

I have the following file hierarchy: Lib > MyModule.rb Lib > MyModule.rb > MyClass.rb

  • 0

I have the following file hierarchy:

Lib > MyModule.rb
Lib > MyModule.rb > MyClass.rb

In MyModule.rb, I have an initialize method:

def initialize(variable, parameter)
  @variable = variable
  @parameter = parameter
end

However, when I try and create an instance of my class, the result is an error:

undefined method: set is not defined for nil

I tried to fix it with this reconstructed version of initialize:

def initialize(variable, parameter)
  @variable = variable
  @parameter = parameter
end

This alleviates the error that I received. However, now I go to create an instance of my class in an HTML.erb file:

<%= MyModule::MyClass.new("string", 1) %>

Here I get an argument error: 2 for 0

Can anyone explain this?

More information as requested:

I’m trying to create a few methods that create html tags as convenience wrappers for commonly used elements. In particular, these utilize the content_tag helper method of rails to create new methods. The plan is eventually to add in nested tag support by using the simple << operator.

Lib/tags.rb

module Tags
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::JavaScriptHelper
  include ActionView::Context

  def initialize(type, content, options, &block)
    @type = type
    @content = content
    @options = block_given? ? nil : options
    @block = block_given? ? block : nil
  end

  def show
    if @block.nil?
      content_tag(@type, @content, @options)
    else
      content_tag(@type, @content, @options) { @block.call }
    end
  end
end

Now this is the lowest level of the module; these are going to be common to all of the tags that I will be implementing. I then have a class in the Tags folder (Lib/tags/div.rb):

module Tags
  class DivTag
    def initialize(content, options, &block)
      super(:div, content, options, &block)
    end
  end
end

Then in my test file main.rb (which is what is routed to when going to localhost)

And this is where I get my error.

  • 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-01T13:55:53+00:00Added an answer on June 1, 2026 at 1:55 pm

    “def Tags” – this is wrong approach, you should use
    class Tags …

    To call “super” in method – class should be inherited from other class, for example
    class DivTag < Tags::Base
    def initialize
    super() # <- Tags::Base#initialize
    end
    end

    by default every new class inheriting from “Object” class, and Object#initialize accept 0 arguments.

    Why you don’t use “content_tag” helper (http://apidock.com/rails/ActionView/Helpers/TagHelper/content_tag) ? Its almost what you want

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

Sidebar

Related Questions

I have the following class hierarchy: class A(object): def __init__(self, filename, x): self.x =
I have following xml file: <ab> <![CDATA[ <table> <tbody> <tr> <th>abcdef</th> </tr> <tr> <p>
I have the following file (above) which seems to be an Unix pipe alt
I have the following File object pointing to a directory via symbolic link, File
I have the following file dupeExtracter.rb to remove duplicate entries from a DB table
Let's assume I have the following file structure: data.py foo = [] bar =
I have the following configuration file for NHibernate : <?xml version=1.0 encoding=utf-8 ?> <hibernate-configuration
I have the following .htaccess file in a directory: RewriteEngine On RewriteCond %{HTTPS} !=on
I have the following text file Eif2ak1.aSep07 Eif2ak1.aSep07 LOC100042862.aSep07-unspliced NADH5_C.0.aSep07-unspliced LOC100042862.aSep07-unspliced NADH5_C.0.aSep07-unspliced What I
I have the following xml file: <xfa:data> <form1> <Page1> <Page2> <contractInfo> ... </contractInfo> <paymentInfo>

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.