#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2015
    Posts
    1
    Rep Power
    0

    Class input always needs to be in strings?


    Why do all the instance variables need to be converted into strings so that when "puts" is called,
    it will be displayed in the command prompt?

    Code:
    class Girls
        def initialize(name,citizenship,chest_size,height,weight)
            @name=name
            @citizenship=citizenship
            @chest_size=chest_size
            @height=height
            @weight=weight
        end
        girl1=Girls.new("Mayara Rizzo","Brazilian","34DD",67,132)
        girl2=Girls.new("Bianca Lopez","Mexican","34D",67,128)
        def to_s
            "#{@name},#{@citizenship},#{@chest_size},#{@height},#{@weight}" #Instance variables must be set as strings.
        end
        def name
            @name
        end
        def citizenship
            @citizenship
        def chest_size
            @chest_size
        end
        def height
            @height
        end
        def weight
            @weight
        end
    end
    
    puts girl1
    puts girl2
    
    end
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    95
    Rep Power
    42
    Could you clarify your question? You're not explicitly converting anything to strings anywhere. So while anything does indeed need to be converted to a string before being printed, this happens implicitly in your code (when you use #{}), so I'm not sure why you say that you need to convert your variables to strings. That happens automatically.

IMN logo majestic logo threadwatch logo seochat tools logo