A
port
of
Ruby
core-‐lib
to
JS
• String,
Regexp,
MatchData
• Array,
Enumerable,
Enumerator
• Numeric
(Integer/Fixnum,
Float)
• Range
• Time,
Hash
coming
soon
97%
Ruby
compliance
• Rubyspec
(1800
specs
5000
asser'ons)
• Ruby
Features
– Block
arguments,
duck-‐typing
• Keep
it
lean,
skipped
features:
– Subclassing
RubyJS
classes,
Tain'ng/trus'ng
– Some
Regexp
func'onality,
No
NilClass,
Boolean
Slide 37
Slide 37 text
How
does
it
compare
to
• CoffeeScript
• Underscore
• Lodash
• Jsclass
• Sugarjs
• PrototypeJS
• Components
Slide 38
Slide 38 text
“Now
I
realise
your
work
is
supposed
to
finish
what
PrototypeJS
once
started.
Help
Ruby
developers
in
wri?ng
JS
–
but
in
a
cleaner
way.”
@nomadcoder,
creator
of
netzke.org
Slide 39
Slide 39 text
Benefits
for
JS
developers
Slide 40
Slide 40 text
One
dependency
<script src="/underscore-1.3.min.js"/>
<script src="/stringjs-0.9.9.js"/>
<script src="/momentjs-1.5.1.js"/>
<script src="/custom_functions.js"/>
One
API
_.map([], (w) -> )
_.chain(arr).(...).value()
S("foo").capitalize().s
moment().format('L')
Slide 43
Slide 43 text
One
API
R( [1] ).map().to_native()
R( [2] ).map().reject().to_native()
R("foo").capitalize().to_native()
R(new Date(…)).strftime(“%y-%m-%d”)
Slide 44
Slide 44 text
One
chain
arr = ['looks', 'feels', 'acts']
str = _.map(arr, (w) ->
S(w).capitalize().s
).join(', ’)
str += " not like Ruby”
S(str).pad(str, 35, '-').s
Slide 45
Slide 45 text
One
chain
arr = R.w('looks feels acts')
arr.map((w) -> w.capitalize() )
.join(", ")
.concat(" like Ruby")
.center(35, '-')
Slide 46
Slide 46 text
One
documenta'on
Slide 47
Slide 47 text
One
documenta'on
Slide 48
Slide 48 text
One
choice
How
much
'me
have
you
spent
switching
libraries?
Backbone,
knockout,
emberjs,
angularjs,
underscore,
prototypejs,
lodash,
stringjs,
jstring,
sugarjs,
components.
Slide 49
Slide 49 text
One
choice
Dual-‐license
• AGPL
• Commercial
Slide 50
Slide 50 text
One
choice
190
USD
/
Dev
Slide 51
Slide 51 text
20
kbytes
minified
and
gzipped
Slide 52
Slide 52 text
It
scales
As
fast
as
the
rest
Slide 53
Slide 53 text
Some
other
features
Slide 54
Slide 54 text
Destruc've
Methods
str = R("foo")
cap = str.capitalize()
cap # "Foo"
str # "foo"
str.capitalize_bang()
str # "Foo"
Slide 55
Slide 55 text
U'lity-‐belt
or
OO-‐style
R("foo") # for 98% of cases
R("foo").center(50).to_native()
R("foo", -> @capitalize() ) # natives
str = new R.String("foo") # For speed
String.new("foo") # Ruby behaviour
R.$String(1) # Ruby: String(1)
Slide 56
Slide 56 text
U'lity-‐belt
or
OO-‐style
str = new R.String("foo")
titleize = (str) ->
str.capitalize_bang()
str.center_bang(50)
str
titleize(str)
" Foo "