Skip to content

Instantly share code, notes, and snippets.

@mykiy
mykiy / hash
Last active April 5, 2018 12:02
hash and symbol
arr = [4,1,2,7,"M","A","V"]
arr.partition { |a| a.is_a? String }.map(&:sort).flatten
p arr
=>
["A","V","M",1,2,4,7]
-------
a = [1, "A", nil, "M", "", '']
a.reject!{|a| a.nil? || a.to_s.empty? }
p a
=>
@mykiy
mykiy / json
Last active April 5, 2018 10:34
json
=> name/value pairs
{
"name":"value"
}
=> supports
number, strings, boolean, nil, array
=>
{
"name":"value",
"array": [ 1,2,3 ],
@mykiy
mykiy / ruby test
Last active April 8, 2018 18:58
Test ruby
1) Explain calling super and calling super() and give some example?
super and super() both inherits methods from parent class. super allows the arguments but super() dont allow the arguments.
Ex:
--
class Niyati
def process(person,work)
"I am #{person} and am a #{work}"
end
end