Tagged Questions
-2
votes
4answers
50 views
ruby - how to set a mixed array with an integer and a hash [closed]
I want to populate an array that has an integer and a hash, something like:
my_a=[Integer,{}]
then for example I am trying to have:
my_a[5,{:direction=>'up'}]
my_a[5,{:speed=>'fast'}]
...
1
vote
1answer
40 views
Adding several items to a Hash in Ruby
I am a ruby beginner and I'm to create my own console-twitter for which whenever a user tweets, the app stores de tweet in a hash.
Initially I was able to successfully do this by using
timeline = []
...
0
votes
2answers
57 views
Algorithm to combine similar hashes in an array
The question is mostly in the title:
given an array
array = [{x: 1, y: "jacksonville"},
{x: 2, y: "atlanta"},
{x: 1, y: "tampa"},
{x: 2, y: "atlanta"},
{x: 2, y: ...
1
vote
2answers
47 views
How to convert specific format array into hash [closed]
I have an array:
ar = ["p=abhZRAh7Un", "a=2", "c=1", "l=3033102", "r=1", "rt=mr", "pid=136330865", "pdid=AiOIhH2vzMPqvhYkxXOxeA%3D%3D", "lks=54.0311", "fks=54.0311"]
and need to convert it into a ...
1
vote
1answer
30 views
fetch mysql prepared statement as array of hashes
I'm struggling with ruby's mysql gem and prepares statements.
I want to end up with the same as I would do with each_hash over the result, but it's nor supported in prepares statements.
So I came with ...
-1
votes
1answer
55 views
Looking for hash exercises in ruby [closed]
I'm not sure if I understand hashes and hashes with arrays in the usage setting, where it's being used as a data structure. I've practiced the fundamentals of the key => value and that seems to be ...
0
votes
1answer
28 views
can I use hash.each even if i'm passing only a string key? Dictionary without definition
This is the error I'm getting. I need to pass a string key to a method that usually accepts string key and string symbol combo
Dictionary
is empty when created`
can add whole entries with ...
-1
votes
2answers
38 views
Hash of array dynamic
I have to create an array during runtime which is stored in a hash.
How can I achieve this in a smart way ?
Following code does not work since services[...] is not an array.
services = {}
...
0
votes
2answers
35 views
How do I force parsing an XML node as hash array?
This is my simplified myXML:
<?xml version="1.0" encoding="utf-8"?>
<ShipmentRequest>
<Message>
<MemberId>A00000001</MemberId>
...
0
votes
2answers
36 views
Hash/Array of objects in Ruby
I'm pretty new to Ruby (I come from a C++ background) and I have an array/hash of objects by their name but I'm having no luck when trying to access their variables. This is my attempt:
class Foo
...
0
votes
1answer
41 views
Michael Hrtl's Ruby on Rails Tutorial ep 5. Changing the hash from :media to media: doesn't work
only on tutorial 5 and I am stumped.
This is similar to a previous post by user1420228, but the answer given didn't really resolve the problem.
In Michael Hartl's application_helper.rb file:
...
1
vote
4answers
57 views
how to change hash keys in the lower case using ruby
Given hash with nested documents:
myHash = {
"MemberId"=>"ABC0001",
"MemberName"=>"Alan",
"details"=>[
{"LineNumber"=>"4.1", "Item"=>"A0001", "Description"=>"Apple"},
...
0
votes
0answers
19 views
How Can I Convert Nested YAML to nested Arrays and OpenStructs in Ruby
How should I convert a series of nested hashes (nested to arbitrary depth) to a series of nested OpenStructs? I'm loading in a big YAML file and I'm not enjoying ...
-1
votes
1answer
46 views
Merging an array of array with an other array
I got this:
first = [['lorem1','lorem1','lorem1',...],['lorem2','lorem2','lorem2',...],...]
second = [value1,value2,value3, ...]
I want to do something like that:
my_array_of_hash = [{value 1 ...
-1
votes
2answers
40 views
Sinatra: Undefined method bytesize for Hash [closed]
I'm creating a Sinatra app that takes an uploaded CSV file and puts its contents in a hash. When I reference this hash in my app.rb like so:
hash = extract_values(path_to_filename)
I keep getting ...