Output
puts
Most of time, we use puts to output a text:
Output:
stdin vs stderr
By default, puts write to stdout, we can output to stderr with this method:
| puts "test"
STDERR.puts "Error"
|
Output:
printf like
To add variable to string with specific format, we can use this syntax:
| nb = 42.2
puts nb
puts "my nb %.2f" % [nb]
|
Output:
debug
With ruby, we can use .inspect with every variable:
| nb = 42
str = "Foo"
float = 42.2
puts nb.inspect
puts str.inspect
puts float.inspect
|
Output:
methods
Every types are class. For evry classes, you can list methods with .methods:
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 | next
**
<=>
<<
>>
<=
>=
==
===
upto
[]
chr
-@
%
&
numerator
denominator
rationalize
*
+
inspect
-
lcm
/
gcd
gcdlcm
ord
size
succ
<
>
to_int
to_s
to_i
to_f
to_r
bit_length
even?
odd?
coerce
div
divmod
modulo
remainder
^
fdiv
magnitude
abs
integer?
zero?
floor
ceil
round
truncate
allbits?
anybits?
nobits?
downto
times
pred
pow
digits
|
~
+@
eql?
arg
rectangular
singleton_method_added
rect
real
imaginary
imag
abs2
angle
phase
conjugate
conj
to_c
polar
i
real?
nonzero?
finite?
infinite?
clone
step
negative?
positive?
quo
dup
clamp
between?
taint
tainted?
untaint
untrust
untrusted?
trust
methods
singleton_methods
protected_methods
private_methods
public_methods
instance_variables
instance_variable_get
instance_variable_set
instance_variable_defined?
remove_instance_variable
instance_of?
kind_of?
is_a?
class
frozen?
then
public_send
method
public_method
singleton_method
tap
define_singleton_method
extend
yield_self
to_enum
enum_for
=~
!~
nil?
respond_to?
freeze
object_id
send
display
hash
singleton_class
itself
!
!=
equal?
instance_eval
instance_exec
__id__
__send__
|