DEV Community

Felix Imbanga
Felix Imbanga

Posted on

String and Date classes

String Class
Formal way to create a new object is with the .new method
.concat method accepts a number as a method, interprets it as an ASCII code, translates it from a single character, and adds it to the end of an original story.
.concat can be replaced with +, you can also drop the ., as well as the parenthesis.

Data Class
Arguments within pp p print or puts need to be seperated with a comma or with interpolation. Date.parse() accepts a string and converts it to a Date object.

String Interpolation + printing
Alternative to .to_s
Easier when it comes to composing strings
Only double quotes interpolate
pp shows the gory technical details, which is usually what you want when debugging code. It calls inspect on whatever object you give it. backend?
puts calls a method .to_s on whichever object you give it. Better for human interaction, frontend?
\n represents a new paragraph or line break. An active character.
\s represents a space between within a line.
Single quotes within double quotes is one way to include a string within a string.
If you want double quotes you need to use the escape character backslash.

"\"Felix\"" ---> "Felix"
The \ before " says treat this next quotation as a character not as the string literal syntactic sugar.
ms = multiline string as long there is one opening and closing quote.

Top comments (0)