Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

ruby make chain method

class SimpleMath
  def initialize
    @result = 0
  end

  #1 add function
  def add(val)
    @result += val
    self
  end

  #2 Subtract function
  def subtract(val)
    @result -= val
    self
  end

  def to_s
    @result
  end
end

newNumber = SimpleMath.new
p newNumber.add(2).add(2).subtract(1)
Comment

PREVIOUS NEXT
Code Example
Ruby :: rails datatypes 
Ruby :: rails remove column 
Ruby :: how to get new line to display in rails 
Ruby :: ruby ||= 
Ruby :: ruby unshift method 
Ruby :: rails get asset path from console 
Ruby :: parse xml ruby 
Ruby :: concatenate arrays in ruby 
Ruby :: ruby pop array 
Ruby :: Ruby ruby-2.6.3 is present on the following stacks: heroku 16 
Ruby :: iterate through values of an object rails 
Ruby :: rails logger info 
Ruby :: rails setup test db 
Ruby :: rails find_by 
Ruby :: how to call ruby private methods 
Ruby :: rails console destroy all 
Ruby :: Rails is not defined 
Ruby :: Blocked host: c25f383bd08f.ngrok.io 
Ruby :: ruby hash print 
Ruby :: devise update password 
Ruby :: rails 
Ruby :: httparty headers 
Ruby :: JSON.parse prevent error ruby 
Ruby :: include module in rails different folder in rails 
Ruby :: rails date field default today 
Ruby :: encryption and decryption in rails 
Ruby :: ruby convert array to set 
Ruby :: rails 7 
R :: r convert string to list of characters 
R :: how to convert all columns of a dataframe into factors in r 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =