Ruby | String * Method
String# * is a String class method in Ruby which is used to returns a new String containing integer copies of the receiver. Here, integer must be greater than or equal to 0.
Syntax: str * Integer
Parameters: Here, str is the required string and integer is the number of copies.
Returns: This method returns the String containing integer copies of the receiver.
Example 1:
# Ruby program to demonstrate # the * method # Taking a string and # using the method puts "Ruby " * 4puts "Hey " * 2 |
Output:
Ruby Ruby Ruby Ruby Hey Hey
Example 2:
# Ruby program to demonstrate # the * method # Taking a string and # using the method puts "Hello " * 0puts "Copy " * 5 |
Output:
Copy Copy Copy Copy Copy
Recommended Posts:
- Ruby | String <=> Method
- Ruby | String + Method
- Ruby | String chr Method
- Ruby | String === Method
- Ruby | String =~ Method
- Ruby | String hex Method
- Ruby | String << Method
- Ruby | String eql? Method
- Ruby | String == method
- Ruby | String chars() Method
- Ruby | String encoding Method
- Ruby | String each_line Method
- Ruby | String center() method
- Ruby | String chomp! Method
- Ruby | String chop! Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



