ruby - Add & Subtract & Calculate -


I am working through RubyMonc and I do not understand what the calculation method is doing. Some explanations, line-by-line will be appreciated. I understand adding and subtracting methods

  def add (* numbers) numbers.inject (0) {| Sum, number | Zodiac + number} end diff subtraction (* numbers) current_ass = numbers Short NumbersEvent (Current_View) {| Current_result, number | Current_result - number} Calculate the end df (* argument) option = argument [-1] .is_a? (Hash)? Arguments.pop: {} option [: add] = if true options.empty? If option [: subtract] end  

  Options = Argument [-1] .is_a? (Hash)? Arguments.pop: {}  

"If the last argument is a hash, then use it for options (and remove it from the logic list), otherwise create an empty hash option".

  option [: add] = true options.empty if?  

This line "If there is no option at all, then add: plus = & gt; right option".


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -