0

Hi

I have my initialise constructor, why won't my function to_hash work ?

def initialize(msg)
    @original_msg = msg.strip.delete(' ')
    s = ["|","^"]
    @chunked_msg = @original_msg.split(s[0])
    @msg_hash.self.to_hash
end

def to_hash
    @chunked_msg.each do |x|
      s =  x.split("=")
      @msg_hash[s[0]] = s[1]
    end
    return @msg_hash
end
1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by benjaminFowl87
0

Solved it, just needed to write self.to_hash

def initialize(msg)
    @original_msg = msg.strip.delete(' ')
    s = ["|","^"]
    @chunked_msg = @original_msg.split(s[0])
    self.to_hash
end

def to_hash
    @chunked_msg.each do |x|
      s =  x.split("=")
      @msg_hash[s[0]] = s[1]
    end
    return @msg_hash
end

Edited by benjaminFowl87: made mistake

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.