Slide 1

Slide 1 text

Active Support @ngtk

Slide 2

Slide 2 text

ActiveSupport͸͔Θ͍͍

Slide 3

Slide 3 text

͓඼ॻ͖ • ActiveSupportͱ͸Կ͔ • CoreExt • AcctiveSupport::* Ҿ༻: http://railsguides.jp/active_support_core_extensions.html

Slide 4

Slide 4 text

Active Supportͱ͸ʁ • Active Support͸Ruby on RailsͷίϯϙʔωϯτͰ ͋ΓɺRubyݴޠͷ֦ுɺϢʔςΟϦςΟɺͦͷଞԣ அతͳ࡞ۀΛ୲͍ͬͯ·͢ɻ • Active Support͸ݴޠϨϕϧͰجຊ෦෼Λఈ্͛͠ ͯ๛͔ͳ΋ͷʹ͠ɺRailsΞϓϦέʔγϣϯͷ։ൃͱ Ruby on RailsͦΕࣗମͷ։ൃʹ໾ཱͯΔ΂͘࡞ΒΕ ͍ͯ·͢ɻ Ҿ༻: http://railsguides.jp/active_support_core_extensions.html

Slide 5

Slide 5 text

CoreExt Hash Class Date DateTime File Float Integer Kernel Module Enumerable Array String Autoload JSON Cache Notifications ActiveSupport:: Configurable Concern TimeZone XmlMini KeyGenerator Logger OrderedHash OrderedOptions Rescuable SecurityUtils TimeWithZone MessageVerifier MessageEncryptor Callbacks ArrayInquirer StringInquirer

Slide 6

Slide 6 text

Object ‘ ’.blank? # => true # blank

Slide 7

Slide 7 text

Object name = ‘yoda’ name.try(:upcase) # => “YODA” # try name = nil name.try(:upcase) # => nil

Slide 8

Slide 8 text

Object sizes = [1, 2, 3, 4, 5] sizes.try { |s| s.sum / s.size } # => 3 sizes = nil sizes.try { |s| s.sum / s.size } # => nil

Slide 9

Slide 9 text

Object content = ‘The Jedi are a fictional and ancient monastic, spiritual, and academic meritocratic organization and the main protagonists in the fictional Star Wars universe, whose origins dates back to circa 25,000 BBY (Before Battle of Yavin; the destruction of the first Death Star).’ content.try { upcase.truncate } # => “THE JED...”

Slide 10

Slide 10 text

String ‘Module’. constantize # => Module # ref 'puni_puni'.dasherize # => “puni-puni" ‘task_id’.humanize # => “Task” ‘test’.inquiry.test? # => true # StringInquirer

Slide 11

Slide 11 text

String ‘active_record/errors’.camelize # => “ActiveRecord::Errors” <<-EOL.strip_heredoc __orange juice EOL => “orange juice”

Slide 12

Slide 12 text

Array Array.wrap(0) # => [0] Array.wrap([0, 1, 2]) # => [0, 1, 2] Array.wrap(nil) # => []

Slide 13

Slide 13 text

Array %w(1 2 3 4 5 6 7 8 9 10).in_groups(3) # => [ ["1", "2", "3", "4"] ["5", "6", "7", nil] ["8", "9", "10", nil] ]

Slide 14

Slide 14 text

Array %w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3) # => [ ["1", "2", "3"] ["4", "5", "6"] ["7", "8", "9"] ["10", nil, nil] ]

Slide 15

Slide 15 text

Array %w(1 2 3 4 5 6 7 8 9 10).in_groups_of(3) # => [ ["1", "2", "3"] ["4", "5", "6"] ["7", "8", "9"] ["10", nil, nil] ]

Slide 16

Slide 16 text

Array %w( a b c d e ).second # => “b” %w( a b c d e ).third # => “c” %w( a b c d e ).fourth # => “d” %w( a b c d e ).fifth # => “e” (1..42).to_a.forty_two # => 42

Slide 17

Slide 17 text

Array [‘apple’, ‘milk’, ‘orange’].to_sentense # => “apple, milk, and orange”

Slide 18

Slide 18 text

Hash options.reverse_merge({size: 25 , velocity: 3}) # `{size: 25 , velocity: 3}.merge(options)`ͱಉ͡ # ண໨͍ͯ͠Δม਺ΛϨγʔόʹͰ͖Δ

Slide 19

Slide 19 text

Numeric 3.kilobytes # => 372 5.megabytes # =>5242880

Slide 20

Slide 20 text

Numeric, Integer # ActiveSupport::Duration , Numeric 4.weeks 5.days 30.seconds 1.month

Slide 21

Slide 21 text

·ͱΊ • ීஈRailsͰ࢖͍ͬͯΔString, Array, Numeric ͳͲ͸͢΂ͯActiveSupportʹΑ֦ͬͯு͞Ε ͯΔΑ • ActiveSupport͸͔Θ͍͍