Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelchretien/d4e9b7dd0ff9ad3a2555b2f1dcbe70d4 to your computer and use it in GitHub Desktop.
Save joelchretien/d4e9b7dd0ff9ad3a2555b2f1dcbe70d4 to your computer and use it in GitHub Desktop.
Compare .NET Linq vs. Ruby Enumerable vs. ActiveRecord Relation

All

Linq

Console.WriteLine(new[] { 1, 2, 3 }.All(x => x > 2)); //=> false

Enumerable

# => false

ActiveRecord

# => false


Any

Linq

Console.WriteLine(new[] { 1, 2, 3 }.Any(x=> x > 2)); //=> true

Enumerable

# => true

ActiveRecord

# => true


Select

Linq

Console.WriteLine(string.Join(", ", new[] { 1, 2, 3 }.Select(x => x + 2))); //=> 3, 4, 5

Enumerable

map() # => true

ActiveRecord

# => true


Min (similar for max)

Linq

Enumerable

a = %w(albatross dog horse) a.min_by { |x| x.length } #=> "dog"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment