class HttpRest
def get(url, params, opts)
end
def post(url, params, opts)
end
def put(url, params, opts)
end
def delete(url, params, opts)
end
end
class Client
attr_reader :response
def initialize(action, url, params, opts)
@response = HttpRest.new.send(action.to_sym, url, params, opts)
end
end
# coding: utf-8
class Calc
attr_reader :num
def initialize(num)
@num = num
end
def plus
self.tap { @num += 1 }
end
def minus
self.tap { @num -= 1 }
end
end
calc = Calc.new(1)
calc.plus.plus.plus.minus.plus.minus
p calc.num
# coding: utf-8
class Calc
attr_reader :num
def initialize(num)
@num = num
end
def plus
@num += 1
self
end
def minus
@num -= 1
self
end
end
calc = Calc.new(1)
calc.plus.plus.plus.minus.plus.minus
p calc.num # 3
def hoge(name)
return "No name" if name.nil?
@name = name
end