Sha256: e5462fa56fed48a08cfd098e682ba129c616f5af82410f7bf4d8b7b82f1946d7
Contents?: true
Size: 708 Bytes
Versions: 1
Compression:
Stored size: 708 Bytes
Contents
require "primus/version" module Primus class Reorder def call(hash) is_hash_empty?(hash) sort_array convert_to_upcase_string end private def is_hash_empty?(hash) if hash.empty? raise RuntimeError.new("This hash is empty") else take_odd_keys(hash) end end def take_odd_keys(hash) hash.each_with_index { |(key,value), index| array << key if index.odd? } end def sort_array array.sort! { |x,y| y <=> x } end def convert_to_upcase_string array.each { |c| string << c.upcase } string end def array @array ||= [] end def string @string ||= "" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
primus_lapus-0.1.0 | lib/primus.rb |