HAML - how to display the value of a variable?

haml, ruby, ruby-on-rails

Solution

I think you may want the `.inspect` method.

= val.inspect

That will show you something like:

#<ShortenedURL @url="the url", @count=0, @etc="etc">

Of course, if you want to dive in to specifics (for example, you only want to show someone the `url` attribute (or whatever attribute you may have), then use that method:

= val.url

Which will show:

the url

Problem

I have a variabla var. If I try to output its value in HAML like =val then I just get the string value of the object which looks like this: `#<ShortenedUrl:0x118c50fa`. But how do I get the value that is in there?

Original source