Questions tagged [enumerable]

"enumerable" refers to an ordering scheme that enables items in a set, sequence or collection to be readily addressed or traversed.

Enumerable is a Ruby module which can be included in other Ruby classes in order to allow iteration via #map/#collect, #select, #each, and so on.

Enumerable also manifests as the class Enumerator (documentation), which is returned when an iteration method is called without a block (e.g., array.each instead of array.each { |x| puts x }).

Enumerable objects may also utilize chained iteration, e.g., array.each.with_indices instead of array.each_with_indices.

Ruby 2.0 also introduces the concept of lazy enumeration.

In .NET, Enumerable is the class that wraps most common LINQ extension methods.

603 questions
0
votes
1 answer

undefined method `assoc' for # (NoMethodError)

I'm trying to return a list of values based on user defined arguments, from hashes defined in the local environment. def my_method *args #initialize accumulator accumulator = Hash.new(0) #define hashes in local environment …
aug2uag
  • 3,379
  • 3
  • 32
  • 53
0
votes
2 answers

How do you put multiple values into one variable or field without using a list and then parsing?

Sometimes there is a need to have multiple values in one variable or database field, even though that violates relational normalization principles. In python and other languages that support lists, that's easy. In others it is not. See insert…
user15972
  • 124
  • 4
0
votes
1 answer

How do I limit loading of a particular Ruby module based on the version of Ruby

Lazy evaluation of enumerables has been included in Ruby 2.0: http://railsware.com/blog/2012/03/13/ruby-2-0-enumerablelazy/ I would like to include this notation (.lazy) in an application I'm writing but for people running any version of Ruby. …
Bob Briski
  • 590
  • 4
  • 13
0
votes
2 answers

Efficient way to group this ruby array of objects

I have an array of instances of model Foo. Foo is an Ohm based data store. Each instance of Foo has an_id and integer attributes such as follows, likes. If there are two instances of Foo with the same an_id, I'd love to add the follows and likes…
randombits
  • 47,058
  • 76
  • 251
  • 433
0
votes
2 answers

How do I extract the hash from an array of one hash?

I'm writing an API parser at the moment, and I'm working on formatting the data nicely. So far, I have the following code: data.each {|season| episodes[season["no"].to_i] = season["episode"].group_by{|i| i["seasonnum"].to_i}} However, the only…
chintanparikh
  • 1,632
  • 6
  • 22
  • 36
0
votes
1 answer

MySql - Using Tables instead of Enum...how do I make a foreign key on a value I have to insert manually?

If the employee is in department "red", I want to make a sub category. Since I am using tables instead of enum for this, I have to insert the static department field values manually. How would I make department red a foreign key to reference table…
dman
  • 10,406
  • 18
  • 102
  • 201
0
votes
1 answer

How to use Ruby's Enumerable .map method to do something similar to map in C++

map(-30, -89.75, 89.75, 0, 360) I'm looking for something like this where: -30 is the input value. -89.75 to 89.75 is the range of possible input values 0 - 360 is the final range to be mapped to I was told there is a way to do this using…
carl crott
  • 753
  • 1
  • 9
  • 21
0
votes
2 answers

Weird behavior for Enumerable.Range(starts, count)

Look at my code. Why does the Enumerable.Range() behave differently whether the start value is 0. class Program { static void Main(string[] args) { var range1 = Enumerable.Range(0, 7); PrintRange(range1); var range2 =…
0
votes
2 answers

Ruby Flatten Enumerable Array Into Multiple Subarrays?

I have the following code: >[['string', 'User'], Foo.all.map {|c| ["number", c.name]}, ['number', 'Average Time']] => [["string", "User"], [["number", "Bar1"], ["number", "Bar2"], ["number", "Bar3"]], ["datetime", "Average Time"]] What I would like…
Noz
  • 6,216
  • 3
  • 47
  • 82
0
votes
3 answers

each_slice ruby with a skip the first x slices

I have a backup script, which I take all the objects in a directory, and then with each slice of 30,000 I back them up to S3. My questions is now that I have over 100,000 objects, I would like to skip to slice number 2 but I am unsure how to do…
tspore
  • 1,349
  • 2
  • 11
  • 14
0
votes
2 answers

Rails Active Record Relations to Enumerable

In certain cases when I get an ActiveRecord Relation I'm experiencing strange behavior with .each on an ActiveRecord::Relation It seems to be when ActiveRecord::Relation delegates :each to :to => :to_a (source) @tasks = Task.find_task(list,…
dylanjha
  • 2,303
  • 4
  • 28
  • 47
0
votes
2 answers

how to check if charCodeAt() is configurable

Here it is described how to check if innerHTML property is configurable and enumerable using Firebug/FF Web Console. How can I check the same for charCodeAt function? Object.getOwnPropertyDescriptor(HTMLElement.prototype,"charCodeAt") return…
tic
  • 4,009
  • 15
  • 45
  • 86
0
votes
5 answers

So maybe I'm not getting the idea in Ruby but I have a question about Enumerables inject

The |m,k| thing kind of throws me off. Does this have anything to do with order of precedence? m standing for 0 (or 1 in some languages) and k for the last in the Array/Hash whatever? So why do people put a number in .inject()? Alternatively, is…
0
votes
2 answers

Convert Expression>> to Expression>

I have some method: public void Foo(Expression> expression) { // foo } and I have variable: Expression>> expression; How I can pass my variable to Foo?
AndreyAkinshin
  • 18,603
  • 29
  • 96
  • 155
0
votes
1 answer

ruby comparing groups of objects on a specific property

Possible Duplicate: More concise version of max/min without the block If I had N number of objects with specific attributes (in this example height), what is a good way to find the max or min? class Person attr_accessor: height end a =…
probably at the beach
  • 14,489
  • 16
  • 75
  • 116