Ruby hashes, getting a key which programatically changes [closed]
Actually it’s almost the same: my_key = :name my_hash = { name: ‘Joe’, age: 52 } my_hash[my_key] #=> “Joe” See http://www.ruby-doc.org/core-2.1.1/Hash.html
Actually it’s almost the same: my_key = :name my_hash = { name: ‘Joe’, age: 52 } my_hash[my_key] #=> “Joe” See http://www.ruby-doc.org/core-2.1.1/Hash.html
The money gem uses I18n. You can either add a valid locale or disable I18n: require ‘money’ Money.new(100).format #=> I18n::InvalidLocale: :en is not a valid locale Money.use_i18n = false Money.new(100).format #=> “$1.00”
I would suggest something like this: /\) (?!.*\))(\S+)/ rubular demo Or if you don’t want to have capture groups, but potentially slower: /(?<=\) )(?!.*\))\S+/ rubular demo (?!.*\)) is a negative lookahead. If what’s inside matches, then the whole match will fail. So, if .*\) matches, then the match fails, in other terms, it prevents a … Read more
You can easily do that by using the strftime method, in this case it would be something like this: Time.now.strftime(“%d/%m/%Y %H:%M”) You can find the complete docs here: http://apidock.com/ruby/DateTime/strftime
Try something like this where you use lower case variable names rather than upper case constant names: def square_root(radicand) a, b = radicand, 1 tolerance = 0.00000000000000000001 while (a – b).abs > tolerance a = (a + b) / 2 b = radicand / a end a end print “Enter the radicand:” radicand = gets.to_f … Read more
>> “Hello world”.reverse => “dlrow olleH”