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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:51:12+00:00 2026-05-25T11:51:12+00:00

I am beginner in Ruby and having trouble understanding this code require_relative ‘custom_page’ module

  • 0

I am beginner in Ruby and having trouble understanding this code

    require_relative 'custom_page'

module Jekyll   
  class Tag < CustomPage
    def initialize(site, base, dir, tag)
      super site, base, dir, 'tag'

      self.data['tag'] = tag
      self.data['title'] = "#{site.config['tag_title_prefix'] || 'Tag: '}#{tag}"
      self.data['description'] = "#{site.config['tag_meta_description_prefix'] || 'Tag: '}#{tag}"
    end
  end

  class Tags < CustomPage
    def initialize(site, base, dir)
      super site, base, dir, 'tags'
      self.data['tags'] = site.categories.keys.sort
      #1# puts self.data['tags']
    end
  end

  class Site
    # generate_tags_categories is called by the custom process function in site_process.rb

    def generate_tags_categories            
      dir = self.config['tag_dir'] || 'tags'
      write_page Tags.new(self, self.source, dir) if self.layouts.key? 'tags'        

      self.categories.keys.each do |tag|
      puts "dd"
      #2# puts tag    
      write_page Tag.new(self, self.source, File.join(dir, tag.slugize), tag)
      end
    end
  end
end

In the above code, the statement puts self.data['tags'] (marked 1) outputs more than 10 values as expected. However, the line puts tag (marked 2) outputs only one value implying that array contains only one value. Isn’t self.categories.keys.each expected to loop through all the values which itself is assigned to self.data['tags']

  • 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-25T11:51:13+00:00Added an answer on May 25, 2026 at 11:51 am

    You may start with ensuring that the ‘categories’ still contain many values before entering the loop:

    puts "categories.keys: #{self.categories.keys.inspect}" # <<- here
    self.categories.keys.each do |tag|
      puts "dd"
      #2# puts tag
    

    If the first puts shows you more than one value, and the loop is called only once, then you may want to investigate what possibly makes the loop break. Maybe write_page throws an exception, catch somewhere up the calling stack?

    When you debug some values, it’s better to use inspect method instead of (automagically called by puts) method to_s. The output of inspect is more debug-friendly.

    It is possible, (however unlikely) that the ‘tag’ contains some control characters which clear the previous output, or something like that. The inspect is always safe. (ok, not always but in most of cases 😉

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

Sidebar

Related Questions

I'm having some beginner problems setting an FFI struct in Ruby. What I want
I'm a beginner at Ruby on Rails so I apologize if this is quite
I'm not a beginner at C# but I really need to increase my understanding,
The very common beginner mistake is when you try to use a class property
I'm sure this is a completely obvious beginner question, but trying to find answers
I am beginner of Ruby on Rails and use Windows for development. I do
I am a Ruby beginner. From the book, I know that a Ruby method
I'm a beginner in ruby-on-rails and I spent my last hour trying to do
I'm a beginner in ruby and in programming as well and need help with
I am a beginner to ruby on rails.But i am quite comfortable with php,

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.