Ruby class instance fields hidden -
This is a very simple question, but I can not understand what is happening here. This is my simple model:
class user attr_accessor: first_name, last_name end I can write first_name and user for the last_name field, and when I call that user through the specified variable, I get this: & gt; U = & gt; # & Lt; Users & gt; This does not show the fields I wrote but when I do this (for the previous and first names):
& gt; U.first_name = & gt; "John" When I call u the whole object is not showing? Like = & gt; # & Lt; User first_name: 'john' lastname: 'smith' & gt; . What do I need to add to my model to get that output? thank you in advanced.
One object is string to_s The method used for human-readable debugging output is inspection . Some environments also use other methods, e.g. pry (or some plugins) uses pretty_inspect for "beautiful" human-readable debugging output. You need to implement those methods. Example:
Inspect class user def "# & lt; # {self.class} first_name: '# {first_name}', last_name: '# {last_name} } '& gt; "End End
Comments
Post a Comment