Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ruby programming Assignment. Please write all the information so I can understand it. Thank you. Create a Ruby definition which adds some small methods to

Ruby programming Assignment. Please write all the information so I can understand it. Thank you.

image text in transcribed

Create a Ruby definition which adds some small methods to the standard String and Array classes which might be of some use in writing a program to generate HTML output. The methods are: Stringhesc Add the hesc method to the string class. It takes no arguments, and returns a copy of the string with each of the characters and & replaced with their appropriate HTML entities. For instance, | "I like less-than (. Between is the original string after processing through hesc. For instance, "f00". tag("i"); returns the string foo. The purpose of the "first word of the argument" rule is to produce a correct closing tag when the tag includ spaces. For instance, "The Many Uses of &".tag("hi color-\"blue"") will return The Many Uses of bamp; Array#tag This simply returns a copy of the array with tag applied to each member. Array#nest This takes a single argument which is a tag under the same rules as Stringttag. It retums a copy of the string, with opening and closing tags added to the front and back. (The added tags are strings.) Place your Ruby code in a file which can be brought in with load. For instance: irb (main) :001:0> load "htmlgen.rb" => true irb(main):002:0> "a "a "a "a kt; b == (a " irb (main):004:0> ["a", "b", "c", "d"). tag("i") -> [" ", " ', ' ", " "} irbimain):005:0> ["a", "b", 'c',"0"].tag("i").nest("tr id=\"foo\"") => ["", "a", "", " ", "", ""] irb(main): 006:0> ("1".."10").to_a.tag('td").nest("tr").join => "12345678910" irb(main): 007:0> ["al","bill", "sally", "jac" ).tag('div color="blue"').rest("div") -> ["
', "
al
", '
bill
", '
sally
", "
joe
", "
"] irb (main): 008:0> ["a", "b", 'c'].nest("a href=\ 'nowhere\"") => ["", "a", "b", "c", " ] class="form e ,"a"); tag >" id=\"100\" ", ""} Create a Ruby definition which adds some small methods to the standard String and Array classes which might be of some use in writing a program to generate HTML output. The methods are: Stringhesc Add the hesc method to the string class. It takes no arguments, and returns a copy of the string with each of the characters and & replaced with their appropriate HTML entities. For instance, | "I like less-than (. Between is the original string after processing through hesc. For instance, "f00". tag("i"); returns the string foo. The purpose of the "first word of the argument" rule is to produce a correct closing tag when the tag includ spaces. For instance, "The Many Uses of &".tag("hi color-\"blue"") will return The Many Uses of bamp; Array#tag This simply returns a copy of the array with tag applied to each member. Array#nest This takes a single argument which is a tag under the same rules as Stringttag. It retums a copy of the string, with opening and closing tags added to the front and back. (The added tags are strings.) Place your Ruby code in a file which can be brought in with load. For instance: irb (main) :001:0> load "htmlgen.rb" => true irb(main):002:0> "a "a "a "a kt; b == (a " irb (main):004:0> ["a", "b", "c", "d"). tag("i") -> [" ", " ', ' ", " "} irbimain):005:0> ["a", "b", 'c',"0"].tag("i").nest("tr id=\"foo\"") => ["", "a", "", " ", "", ""] irb(main): 006:0> ("1".."10").to_a.tag('td").nest("tr").join => "12345678910" irb(main): 007:0> ["al","bill", "sally", "jac" ).tag('div color="blue"').rest("div") -> ["
', "
al
", '
bill
", '
sally
", "
joe
", "
"] irb (main): 008:0> ["a", "b", 'c'].nest("a href=\ 'nowhere\"") => ["", "a", "b", "c", " ] class="form e ,"a"); tag >" id=\"100\" ", ""}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

Have roles been defined and assigned?

Answered: 1 week ago

Question

Are these written ground rules?

Answered: 1 week ago