Skip to content

Instantly share code, notes, and snippets.

View anderslime's full-sized avatar

Anders Emil Pouplier anderslime

  • Copenhagen
View GitHub Profile
### Keybase proof
I hereby claim:
* I am anderslime on github.
* I am anderslime (https://keybase.io/anderslime) on keybase.
* I have a public key ASDRw8omoxsupCOOTodV5rb_ZK95b5xIJJLhrmQWhX1Grgo
To claim this, I am signing this object:
@anderslime
anderslime / gist:7119000
Last active December 26, 2015 07:59
Do not use struct for serious objects. That also include inheritans. Why:
class Contact < Struct.new(:email, :password); end
# 1: It has a #to_a method that returns an array
# of the values of the Struct.
contact = Contact.new("my@email.dk", "secret")
Array(contact) # => ["my@email.dk", "secret"]
# 2: It sets all initialization arguments to nil as default
Contact.new # => #<struct Contact email=nil password=nil>
provider_id = 4
contact = Contact.find_by_name_and_provider_id("Jakob Kristensen", provider_id)
locations =
Location.
active.
where(:provider_id => provider_id).
select {|location| location.primary_contact == contact }