ruby - Trying to define a method within a method within a class -


I'm trying to pass a sample and I'm getting an error, "undefined method` first_word 'inferno" : String "

I have defined the 'first_word' method, this class method is within the 'title'. I am having trouble determining that I can class this class on a string in the 'Method' How can I call the 'first_word' method.

Tip:

Description 'Title' first letter O @ book.title = "inferno" @ book.title.should == "Inferno" and

  to each word "Do @ book.title =" Stuart Little "@ book.title. Should == "Stuart Little" should describe every word except 'end' ... 'specify' article 'specify' 'do' book.title = "alexander the great" @ book.title.should == "Alexander the Great" Finally specify 'A' dot @ book. Title = "bookmarking a mockingbird" @ book.title.should == "Specify the end" to kill a millingbird "'A' Do @ boo K.title = "to eat an apple in a day" @ book.title.should == "an app eating a day" end-end 'conjunctions' do @ book.title = "war and peace" @ book.title Tell. == "War and Peace" finally specify 'Prepons' dot @ book. Title = "Love in the time of Haider" @ book.title.should == "Love in the Time of Cholera" The End END Describes' Always Let's specify ... 'specify' I 'do @ book.title = "What do I want to know when I was 20" @ book.title.should == "What did I want when I was 20" Specify the end "first word" do @ book.title = 'man in iron mask' @ book.title.should == "The man in the iron mask" and end   

My code:

  class book attr_accessor: title def initialise @title end def title = (str) def first_word self [0,1]. Save [S, I "If", "and", "in"] str = str.split.map {| W | Cap_except.include? (W)? W: w.capitalize} .join ("") .first_word @title = str end   

termination

You are calling a string like " foo "on first_ward . Length . You have not defined first_ward on the string class.

You have defined a method that you to a string, like, first_word ("foo") .

Unrelated, but why are you trying to block such method definitions?

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -