[Solved] ruby how to match a substring [closed]

To get an input out of the whole file: ▶ input = input[/PLAY RECAP.*?^(.+?)^localhost/m, 1] To hashify the result: ▶ input.scan(/(\S+) : ok=(\w+)/).to_h #⇒ { # “ec2-123.compute-1.amazonaws.com” => “16”, # “ec2-456.compute-1.amazonaws.com” => “11”, # “ec2-766.compute-1.amazonaws.com” => “40” # } To sort by host name (thx Wiktor Stribiżew for the reminder.) input.scan(/(\S+) : ok=(\w+)/) .to_h .sort_by … Read more

[Solved] Feching user’s current location tips [closed]

So you really have two options. The first, and most likely to be accurate, is to ask the user through their browser via javascript, what their location is. HTML5 allows you to do this through geolocation: https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation The basics are as follows: navigator.geolocation.getCurrentPosition(function(position) { do_something(position.coords.latitude, position.coords.longitude); }); Obviously, this requires the user to agree to … Read more

[Solved] Can somenone translate this from Ruby to Python. Its a basic map function [closed]

So to answer your questions regarding operators like << or ||= []: << appends an element to an array (or appends strings), in the case above it’s used to append the comment object to either the results array or or the threaded thingy. ||= basically means, if left-hand-side is undefined then evaluate & assign right-hand-side … Read more

[Solved] Ruby index assignment [closed]

Ref Array method of ary[start, length] = obj or other_ary or nil → obj or other_ary or nil items[1,0] = [“bottle”, “my”] Here, 1 is Index & Length is 0 As per the documentation ‘Elements are inserted into the array at start if length & index are zero.’ For Ex:- a = [‘A’] a[0, 0] … Read more

[Solved] What’s the difference between “#{self.key}” and “vynd6tg1hh”? [closed]

def get_wistia_media Wistia::Media.get(wistia_key) end Is calling a class method def wistia_key “#{self.key}” end Is defined as an instance method, try def self.wistia_key def wistia_key “vynd6tg1hh” end Just returns a string that will always be the same. 2 solved What’s the difference between “#{self.key}” and “vynd6tg1hh”? [closed]

[Solved] Ruby Program to print pattern [closed]

You can use collection, map or each for this data = {a: [1,2,3,4,5,6,7,8,9],b: [1,2,3,4,5,6],c: [2,3,4,5,6,7]} data.map{|k,v| (1..9).map{|a| data[k].include?(a) ? k.to_s.upcase() +a.to_s : ‘ ‘}} 9 solved Ruby Program to print pattern [closed]

[Solved] Very Basic Ruby puts and gets

It always helps if you include the error. There are two ways to fix that error: Interpolate the value: puts “you would like #{number} much better” Turn it from a number to a string: puts “you would like ” + number.to_s + ‘much better’ The former, #{…} syntax, evaluates the content of the braces as … Read more

[Solved] Keep real numbers in Ruby language [closed]

In Ruby 1.8 & 1.9, floats are never immediates, so all floats require a new memory allocation. In Ruby 2.0.0, on 64 bit systems, many floats are now immediate. This means that the typical floats don’t require memory allocation & deallocation anymore, so much faster operations. Ruby stores its values in a pointer (32 or … Read more