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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:20:42+00:00 2026-05-25T02:20:42+00:00

Previously on #ruby somebody told me that I do not need to use @name

  • 0

Previously on #ruby somebody told me that I do not need to use @name and self.name unless the variable name is already defined locally, which I was happy to learn would make my code a bit neater I thought. After playing around and adjusting a few of my classes I noticed that I could not access name (it is nil) after setting @name in initialize in the subclass.

The following works:

module EnvyGeeks
  class Attributes

    attr_accessor :persons_name

    def initialize(name)
      @persons_name = name
    end

  end
end

module EnvyGeeks
  class MyAttributes < Attributes

    def initialize(name)
      @persons_name = name
      puts persons_name
    end

  end
end

envygeeks = EnvyGeeks::MyAttributes.new("Jordon")

The following fails:

require "pp"

module Jekyll
  class MyPages < Page

    def initialize(site, base, page)
      @name = page.split("/")
      pp name # => nil
    end

  end
end

That class taps off this super class:
https://github.com/mojombo/jekyll/blob/master/lib/jekyll/page.rb

I’m a bit confused why name would not be working in this instance but in the first it does?

More information:

From: ./pages.rb @ line 19 in Jekyll::MyPages#initialize:

    14:     def initialize(site, base, page)
    15:       @site = site
    16:       @dir  = "/"
    17:       @base = base
    18:       
 => 19:       binding.pry
    20:       @name = page.split("/")
    21:       if name.length > 1
    22:         name.pop if name.last =~ /index.html$/
    23:         name = name.join("/") if name.length > 1


pry(#<Jekyll:Page @name=nil>)> @name = page.split("/") => ["index.html"]
pry(#<Jekyll:Page @name=["index.html"]>)> name => nil
  • 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-05-25T02:20:43+00:00Added an answer on May 25, 2026 at 2:20 am

    Which version of Ruby is this? On 1.9.2 it works fine.

    require 'jekyll'
    require 'pp'
    
    module Jekyll
    
      class TestPage < Page
        def initialize(site,base,page)
          @name = "test"
          puts name # => test
          pp name # => "test"
        end
      end
    
    end
    
    a = Jekyll::TestPage.new("","","")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I previously asked a question that I still have not been able to solve:
Previously, I had a class that wrapped an internal System.Collections.Generic.List<Item> (where Item is a
I'm been developing Ruby on Rails previously. I'm now looking at an ASP.net web
I'm writing a program in Ruby that downloads a file from an RSS feed
I've previously written some selenium tests using ruby/rspec, and found it quite powerful. Now,
I have created a Gemfile in my rack application (that previously used .gems). When
Based on my previous thread : RVM installed by Ruby not working? where i
Previously I have asked to strip text from a field and convert it to
Previously, I asked the question . The problem is the demands of our file
Previously I've asked about inserting a column into a dataset . I now have

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.