I have to create a method that receives two strings , this method will create an index.html file and put each of the received strings as a paragraph .
I have to create a method that receives two strings , this method will create an index.html file and put each of the received strings as a paragraph .
To create a file you can use
File.open
with the option"w"
, and to write to the file use thewrite
; for instance:By specifying
*strings
as a parameter, it allows you to call the method with one or more strings , you don't limit the method to just one.For example, you can call the above function like this:
Which would create the index.html file with the following content:
You could also use heredoc and call
File.write
, making your code slightly more efficient and readable:Result: