[Solved] What is za and what is next

String#tr allows c1-c2 as a shorthand notation for a range of characters: a-z expands to abcdefghijklmnopqrstuvwxyz b-z expands to bcdefghijklmnopqrstuvwxyz b-za is b-z followed by a single a, i.e. bcdefghijklmnopqrstuvwxyza Finally s.tr!(‘a-z’, ‘b-za’) replaces each letter by the next one in the alphabet using this mapping: from_str: abcdefghijklmnopqrstuvwxyz to_str: bcdefghijklmnopqrstuvwxyza solved What is za and … Read more

[Solved] Compare keys of array in RUBY

I corrected your code also as per your need, and solved further, $ArrayX = [8349310431,8349314513] $ArrayY = [667984788,667987788] $ArrayZ = [148507632380,153294624079] $range_map = $ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort $ArrayX = [8349310431,8349314513] => [8349310431, 8349314513] $ArrayY = [667984788,667987788] => [667984788, 667987788] $ArrayZ = [148507632380,153294624079] => [148507632380, 153294624079] $range_map = Hash[$ArrayX.zip([$ArrayY.map(&:to_i), $ArrayZ.map(&:to_i)].transpose).sort] => {8349310431=>[667984788, 148507632380], 8349314513=>[667987788, 153294624079]} keys = $range_map.keys … Read more

[Solved] How to find out the number of records in a table? [closed]

It would be something like this on your model: def self.pending_count where(status: 0).count end def self.in_progress_count where(status: 1).count end def self.finished_count where(status: 2).count end Then you can just call Model.pending_count (or the other methods) wherever you need it. solved How to find out the number of records in a table? [closed]

[Solved] Regex for price with   and comma [closed]

Here’s how I’d do it: str = “8 560,90 cur.” str.gsub(/[^\d,]/, ”).to_i # => 8560 This removes every character that isn’t a digit or a comma, yielding “8560,90”, then calls to_i on it, which gives 8560. This will work for any string as long as you want every digit before the first comma to be part … Read more

[Solved] Converting an array of numbers to characters ruby [closed]

You create instance of Encrypted method, but you set @code = 2, @string = “Hello” and @encrypted = []. So if you call @encrypted[0], ruby return nil. So you can modify your class like this: class Encrypt def initialize(code, string) @code, @string, @encrypted = code, string, [] end def to_byte @string.each_byte { |c| @encrypted << … Read more

[Solved] How to parse time given an hours [closed]

Parse the hour with Time#strptime hour = 4 Time.strptime(“#{hour}”, “%H”) => 2015-11-02 04:00:00 +0000 And then parse with Time#strftime if you’re interested in the formatting. Time.strptime(“#{hour}”, “%H”).strftime(“%H:%M”) => “04:00” solved How to parse time given an hours [closed]

[Solved] Initialize Ruby codes error

class Dog def set_name(name) @dogname = name end def get_name return @dogname end def talk return “awww” end def initialize(title, description) @title = title @description = description end end #That will cause an error because your new method have two arguments. doggy = Dog.new bogart = Dog.new(‘The Book’, ‘The road not taken’) bogart.set_name(‘Sam’) puts bogart.get_name … Read more

[Solved] Rails: Remove Curly Braces in Array [closed]

@temp = SalesOrder.where(“status > ?”, 0).ids items = SalesOrderItem.where(sales_order_id: @temp).where.not(product_id: nil) total = items.to_a.group_by(&:product_id).each_with_object({}) do |(product_id, quantity), total| total[Product.find(product_id.to_i).name] = quantity.map(&:quantity).map(&:to_f).sum end @top_five = total.sort_by { |k, v| v }.reverse! Check this. It should work. If any errors, ping me, I will update it PS: your code is not optimized at all. All of this … Read more