forked from zmack/ruby-things
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods.rb
75 lines (58 loc) · 853 Bytes
/
methods.rb
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
# defining methods
def foo(bar)
bar * 2
end
# optional returns, optional parens
# last value of the method gets returned, parens can be ommitted
foo(10) # => 20
foo 10 # => 20
def foo bar
10
end
def foo(cal, vaca = 10, bar = 10)
return :moo, :val if false
return :cal
bar * 2
end
def bar(cal:, vaca: 2, bar: 10)
puts cal
puts vaca
puts bar
end
def other_method(value, is_true: true, print: false)
if print_things
puts value
end
if is_true
!!value
else
!value
end
end
a = 4
#if a == 3
#p :foo
#elsif a == 2
#p :bar
#else
#p :moloz
#end
#case a
#when 3
#p :moloz
#when 2
#p :etc
#else
#p :bla
#end
#case a
#when Fixnum
#puts "Fixnum"
#when String
#puts "String"
#when Symbol
#puts "Symbol"
#end
# puts "foo" unless (a == 3)
# => test/essentials_test.rb
# => classes.rb