"Рай и Ад - это взгляд на вещи. Это не физическое место, это отношение, то, как Вы смотрите на вещи." - Ошо
imported_emails = [ 'john@doe.com', 'janet@doe.com' ]
existing_emails = [ 'john@doe.com', 'janet@doe.com' , 'fred@mercury.com' ]
puts 'already imported' if (imported_emails - existing_emails).empty?
tags_post1 = [ 'ruby', 'rails', 'test' ]
tags_post2 = [ 'test', 'rspec' ]
common_tags = tags_post1 & tags_post2
followeds1 = [ 1, 2, 3 ]
followeds2 = [ 2, 4, 5 ]
all_followeds = followeds1 | followeds2
data = [
{
name: 'Christophe',
location: 'Belgium'
},
{
name: 'John',
location: 'United States of America'
},
{
name: 'Piet',
location: 'Belgium'
},
{
name: 'François',
location: 'France'
}
]
data.sort_by { |hsh| hsh[:location] }
Product = Struct.new(:id, :category_id)
products = [
Product.new(1, 1),
Product.new(2, 2),
Product.new(3, 3),
Product.new(4, 1),
Product.new(5, 3),
Product.new(6, 5),
]
products = products.uniq &:category_id
books = [
'The Ruby Programming Language',
'Programming Ruby 1.9 & 2.0: The Pragmatic Programmers\' Guide (The Facets of Ruby)',
'Practical Object-Oriented Design in Ruby: An Agile Primer',
'Eloquent Ruby',
'Ruby on Rails Tutorial: Learn Web Development with Rails'
]
books = books.grep(/[Rr]ails/)
def method
# …
[*products]
end