Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

5 random ruby tips

472 views

Published on

for lightning talk at Ruby Meetup
http://www.meetup.com/Singapore-Ruby-Group/events/220551234/

Published in: Software
  • Be the first to comment

5 random ruby tips

  1. 1. 5 Random Ruby Tips
  2. 2. about me ● Akira Hirakawa ● VP Engineering at Burpple ● Ruby, Go, iOS Engineer ● https://github.com/akirahrkw ● http://www.akirahrkw.com
  3. 3. 1: levenshtein distance ● measure the difference between 2 sequences ● “Ruby” and “Rugby” ● can be used to implement suggest feature ● http://en.wikipedia.org/wiki/Levenshtein_distance ● https://github.com/akirahrkw/levenshtein-distance distance = "Ruby".levenshtein_distance("Rugby") # distance is 1 distance = "saturday".levenshtein_distance("sunday") # distance is 3 distance = "akira".levenshtein_distance("hirakawa") # distance is 5
  4. 4. 2: Rails4.2 + jsonb ● Rails4.2 supports jsonb type in Postgres 9.4 ● jsonb vs json ○ jsonb is binary, json is string ○ search is faster than json, storage size is bigger than json ○ if you prioritise storage efficiency, use json ○ if search efficiency, use jsonb ● we haven’t used jsonb in practice yet :( ● http://www.postgresql.org/docs/9.4/static/datatype-json.html
  5. 5. 3: protected method ● protected method can be called with a receiver ● but the receiver must be in the inheritance hierarchy of the caller
  6. 6. 4: each ● concurrently do each multi-array keys = [1, 2, 3, 4, 5] values = [‘ruby’, ‘swift’, ‘objc’, ’java’, ’python’] keys.zip(values).each do |key, value| p key p value end
  7. 7. 5: frozen constant ● constant is mutable module CODE LANGUAGES = [“ruby”, “python”, “objc”, “swift”] end module CODE LANGUAGES = [“ruby”, “python”, “objc”, “swift”].freeze end module CODE LANGUAGES = [“ruby”, “python”, “objc”, “swift”].map!(&:freeze).freeze end
  8. 8. Thank you

×