Skip to content
This repository was archived by the owner on May 23, 2020. It is now read-only.

Commit dd77549

Browse files
i/o
1 parent 9d01e2b commit dd77549

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ will read the statement, evaluate it, print the result, and then give the contro
1313
rather that braces for defining scopes. To exit the shell, type **quit()**. This will bring the control back to command prompt.
1414
The other way to execute ruby is by writing script in a file with .rb extension. To run this file, write in command prompt ```ruby hello.rb``` where hello.rb is the ruby script file.
1515

16-
### Data Types and Varibales
16+
### Data Types and Variables
1717
Variables are dynamically typed in Ruby. Hence mentioning data type is not required while declaring a variable.
1818
```ruby
1919
a = 100
@@ -44,3 +44,20 @@ $global #100
4444
changeit
4545
$global #0
4646
```
47+
**nil** is an object. When nil is assigned to a variable, it does not mean that the variable is empty. It is storing the nil object of **NilClass*.
48+
```ruby
49+
x = nil
50+
x.nil? # true
51+
x.class #NilClass
52+
```
53+
54+
### Input to program
55+
**gets** is used to take input from user. By default, it will save user's input in string format. To accept input in other format, explicit typecast is required.
56+
```ruby
57+
x = gets
58+
x.class #String
59+
y = Integer(gets)
60+
y.class #Integer
61+
```
62+
Similarly, other data types casting can also be done.
63+
For printing to console, **print** or **puts** is used. The later adds a new line by default to the parameter, while the former does not.

0 commit comments

Comments
 (0)