lightning talk 2

Post on 19-Jan-2015

87 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

Shitceptions

Wednesday, June 19, 13

github.com/theverything theverythingy

Active Support

Wednesday, June 19, 13

require 'active_support/all'require 'active_support/core_ext'require 'active_support/core_ext/hash'require 'active_support/core_ext/hash/slice'

Active Support all up in your Rails

To add it to any project

gem 'activesupport'

Wednesday, June 19, 13

Active Support adds extensions to...

Wednesday, June 19, 13

Active Support adds extensions to...Array, BigDecimal, Class, Date, DateTime, File, Float, Hash, Integer, Kernel, Module, Numeric, Object, Process, Range, String, and Time

Wednesday, June 19, 13

String "hello world".truncate(9)=> "hello ..."

'person'.pluralize=> "people"

'people'.singularize=> "person"

"hello world".titleize=> "Hello World"

"Hello World!!".parameterize=> "hello-world"

"hello_world".camelize=> "HelloWorld"

"HelloWorld".underscore=> "hello_world"

Wednesday, June 19, 13

Integer &Enumerable

1.ordinalize=> "1st"

2.ordinalize=> "2nd"

3.ordinalize=> "3rd"

4.ordinalize=> "4th"

[1, 2, 3, 4, 5].sum=> 15

Wednesday, June 19, 13

[1, 2, 3, 4, 5].second=> 2

[1, 2, 3, 4, 5].third=> 3

[1, 2, 3, 4, 5].fourth=> 4

[1, 2, 3, 4, 5].fifth=> 5

(1..100).to_a.forty_two=> 42

["one", "two", "three"].to_sentence=> "one, two, and three"

[1, 2, 3, 4, 5, 6, 7].in_groups_of(2)=> [[1, 2], [3, 4], [5, 6], [7, nil]]

Array

Wednesday, June 19, 13

[1, 2, 3, 4, 5].second=> 2

[1, 2, 3, 4, 5].third=> 3

[1, 2, 3, 4, 5].fourth=> 4

[1, 2, 3, 4, 5].fifth=> 5

(1..100).to_a.forty_two=> 42

["one", "two", "three"].to_sentence=> "one, two, and three"

[1, 2, 3, 4, 5, 6, 7].in_groups_of(2)=> [[1, 2], [3, 4], [5, 6], [7, nil]]

Array

Wednesday, June 19, 13

Hash{ one: "hello", two: "world", three: "yay" }.to_query=> "one=hello&three=yay&two=world"

{ one: "hello", two: "world", three: "yay" }.slice(:one, :three)=> {:one=>"hello", :three=>"yay"}

{ one: "hello", two: "world", three: "yay" }.except(:one)=> {:two=>"world", :three=>"yay"}

Wednesday, June 19, 13

to_param

["one", "two", "three"].to_param=> "one/two/three"

class Post < ActiveRecord::Base def to_param "#{created_at.strftime("%m-%d-%y")}-

#{title.parameterize}" endend

post_path(@post) # => "6-19-13-hello-world"

Wednesday, June 19, 13

Questions?

github.com/theverything theverythingy

Wednesday, June 19, 13

top related