Ruby Integer to_s function with example Last Updated : 03 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report The to_s function in Ruby returns a string containing the place-value representation of int with radix base (between 2 and 36). If no base is provided in the parameter then it assumes the base to be 10 and returns. Syntax: number.to_s(base) Parameter: The function takes the number and a base to which is to be converted. If no base is provided in the parameter, then the default parameter is assumed to be 10. Return Value: The function returns a string containing the place-value representation of int with the given radix base. Example #1: Ruby # Ruby program for to_s function # Initializing the number num1 = 10 num2 = 16 num3 = 298 num4 = 183 # Prints the string after # conversion into base puts num1.to_s puts num2.to_s puts num3.to_s(2) puts num4.to_s(8) Output: 10 16 100101010 267 Example #2: Ruby # Ruby program for to_s function # Initializing the number num1 = 120 num2 = 189 num3 = 132 num4 = 8 # Prints the string after # conversion into base puts num1.to_s(5) puts num2.to_s(20) puts num3.to_s(2) puts num4.to_s Output: 440 99 10000100 8 Comment More infoAdvertise with us G gopaldave Follow Improve Article Tags : Ruby Ruby-Methods Ruby Integer-class Similar Reads Ruby | Loops (for, while, do..while, until) Looping is a fundamental concept in programming that allows for the repeated execution of a block of code based on a condition. Ruby, being a flexible and dynamic language, provides various types of loops that can be used to handle condition-based iterations. These loops simplify tasks that require 5 min read Ruby Programming Language Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. Ruby is a pure Object-Oriented language developed by Yukihiro Matsumoto. Everything in Ruby is an object except the blocks but there are replacements too for it i.e procs and lambda. The objective of Rubyâs develop 2 min read Ruby on Rails Introduction Ruby on Rails or also known as rails is a server-side web application development framework that is written in the Ruby programming language, and it is developed by David Heinemeier Hansson under the MIT License. It supports MVC(model-view-controller) architecture that provides a default structure f 6 min read Ruby on Rails Interview Questions And Answers Ruby on Rails, often shortened to Rails, is a server-side web application framework written in Ruby under the MIT License. Rails is known for its ease of use and ability to build complex web applications quickly. It was created by David Heinemeier Hansson and was first released in 2004. Now, Over 3. 15+ min read Ruby - String split() Method with Examples split is a String class method in Ruby which is used to split the given string into an array of substrings based on a pattern specified. Here the pattern can be a Regular Expression or a string. If pattern is a Regular Expression or a string, str is divided where the pattern matches. Syntax: arr = s 2 min read Ruby Tutorial Ruby is a object-oriented, reflective, general-purpose, dynamic programming language. Ruby was developed to make it act as a sensible buffer between human programmers and the underlying computing machinery. It is an interpreted scripting language which means most of its implementations execute instr 6 min read Ruby | Data Types Data types in Ruby represents different types of data like text, string, numbers, etc. All data types are based on classes because it is a pure Object-Oriented language. There are different data types in Ruby as follows: NumbersBooleanStringsHashesArraysSymbols Numbers: Generally a number is defined 3 min read Ruby | Case Statement The case statement is a multiway branch statement just like a switch statement in other languages. It provides an easy way to forward execution to different parts of code based on the value of the expression. There are 3 important keywords which are used in the case statement: case: It is similar to 3 min read Hello World in Ruby Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. Hello World the program is the most basic and first program when we start a new programming language. This simply prints Hello World on the screen. Below is the program to write hello world". How to run a Ruby Prog 2 min read Ruby For Beginners Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan. This article will cover its basic syntax and some basic programs. This article is divided into various sections for various topi 3 min read Like