'*Error in evaluation* while inserting an instance into an Array

I have Category class:

  class Category
    include Comparable

    attr_reader :name

    ##
    # Initialize the Category
    #
    # +name+ is the name of the current Category
    # +context+ is the Liquid:Tag context
    #
    def initialize(name, context)
      @name = name
      @context = context
    end

    ##
    # Compare this Category against another Category.
    # Comparison is a comparison between the 2 names.
    #
    def <=>(other)
      return nil unless name.is_a? String
      name <=> other.name
    end
  end

I want to create Categories class that takes an array of strings and convert it into an array of Categorys. Here is what I wrote:

  class Categories
    ##
    # Initialize the list of categories by passing a list String
    #
    # +category_names+ A list of strings representing a list of categories.
    # +context+ is the Liquid:Tag context
    #
    def initialize(category_names, context)
      category_names = [category_names] unless category_names.is_a? Array
      byebug
      @category_list = category_names.map{|string| Category.new(string, context)}
    end
  end

When I'm trying to debug I have the following:

(byebug) category_names.map
#<Enumerator: ["Heroku"]:map>
(byebug) cat = Category.new("Heroku", context)                                                                          
#<Jekyll::Category:0x00000002a85000>
(byebug) cat.name
"Heroku"
(byebug) @category_list = [cat]
*Error in evaluation*

It fails with an error *Error in evaluation*. I cannot figure why. Can someone help me?



Solution 1:[1]

This may be because the Category has binary attributes that can not convert to a valid string, the error raised from byebug:

https://github.com/deivid-rodriguez/byebug/blob/ddad523427d4ccb5c94aa4858b64b4bbf3d0399c/lib/byebug/helpers/eval.rb#L119

      def safe_to_s(var)
        var.to_s
      rescue StandardError
        "*Error in evaluation*"
      end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fangxing