Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

integer
encoding
ruby
communitycreator

What is integer.chr in Ruby?

okwudili onyejiaku

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

chr is a property of the Integer instance used to get the string containing the character represented by the integer’s value according to encoding.

Syntax

integerValue.chr

Return value

This property returns a string that contains the character representing the integer value integerValue according to encoding.

Example

Let’s look at the code below:

# create some integer values
int1 = 65
int2 = 100
int3 = 200
int4 = 70

# get character representations
puts int1.chr
puts int2.chr
puts int3.chr
puts int4.chr
Getting the character representations of Integer values

Explanation

  • Line 2 to 5: We create some integer values.
  • Lines 8 to 11: We get the character representations of the integer values according to encoding using the chr property. The results are printed to the console.

RELATED TAGS

integer
encoding
ruby
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring