Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RubyJS at rubyconf.tw
Search
hasclass
December 07, 2012
Programming
2
540
RubyJS at rubyconf.tw
lightning talk
hasclass
December 07, 2012
Tweet
Share
More Decks by hasclass
See All by hasclass
RubyJS
hasclass
1
220
Other Decks in Programming
See All in Programming
RubyVM を PHP で実装する 〜Hello World を出力するまで〜
memory1994
PRO
1
490
イベントストーミングによるオブジェクトモデリング・オブジェクト指向プログラミングの適用・開発プロセスの変遷・アーキテクチャの変革 / Object modeling with Event Storming.
nrslib
12
3.2k
PHPでOfficeファイルを取り扱う! PHP Officeライブラリを プロダクトに組み込んだ話
hirobe1999
0
840
IntelliJ IDEA を知らなかった 自分に教えたい小ネタ集 / IntelliJ IDEA Hints for My Past Self
mackey0225
3
180
DDD, necessary but insufficient: physical design principles for microservices
cer
PRO
0
2.2k
9年開発を牽引して見えてきた、共通化すべきものと個別でつくるもの ~プログラム言語~
shinout
1
280
Dockerで始めるAWS Lambda開発
stutkhd0709
14
2.5k
Parallel Socket Communication in Swift
s_shimotori
0
260
Deep Dive 大規模システムアーキテクチャ/開発組織エンジニアリング / Deep Dive Large-Scale System Architecture, Development Organization Engineering
nrslib
15
2.9k
ドメイン・ファーストで考える問題解決に役立つモデル設計 / Domain First Model Design
suzushin54
1
1.5k
導入から5年が経って見えた Datadog APM 運用の課題
bgpat
2
540
SwiftUI, Jetpack Composeの導入で変化した「家族アルバム みてね」のアプリ開発体験
hicka04
6
400
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
72
8.2k
Happy Clients
brianwarren
91
6.3k
Web Components: a chance to create the future
zenorocha
304
41k
Why Our Code Smells
bkeepers
PRO
330
56k
The Mythical Team-Month
searls
214
42k
Build The Right Thing And Hit Your Dates
maggiecrowley
23
1.9k
GraphQLとの向き合い方2022年版
quramy
28
12k
Making the Leap to Tech Lead
cromwellryan
123
8.4k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
101
6.6k
Designing with Data
zakiwarfel
94
4.8k
Navigating Team Friction
lara
177
13k
Fontdeck: Realign not Redesign
paulrobertlloyd
75
4.8k
Transcript
RubyJS alpha www.rubyjs.org twi5er.com/hasclass
50 slides in 5 minutes
None
None
A port of Ruby core-‐lib to JS • String,
Regexp, MatchData • Array, Enumerable, Enumerator • Numeric (Integer/Fixnum, Float) • Range • Time, Hash coming soon
JS Methods Array jjjjjjjjjjjjj Enumerable Fixnum Float jjjj Integer
Kernel Matchdata Numeric Range Regexp jj String jjjjjjjjjjjjj
RubyJS Methods Array jjjjjjjjjjjjj................................. ............................ Enumerable .............................................. Fixnum ...........................
Float jjjj.............................. Integer .................... Kernel ... Matchdata ..................... Numeric ....................... Range ...................... Regexp jj...................... String jjjjjjjjjjjjj................................ ...........................
Compliant to Ruby No surprises.. Rubinius Rubyspecs ported
to JS
str = "a"
str = R("a”) #=> R.String
str = R("a") str.capitalize() #=> R.String #=> A
str = R("a") str.capitalize() .upto('C') #=> R.Enumerator
str = R("a") str.capitalize() .upto('C’) .each_cons(2, function (a,b) {
R.puts("#{a} to the #{b}") }) # A to the B # B to the C
str = R("a") str.capitalize() .upto('C’) .to_a() #=> R.Array #=>
[A, B, C]
str = R("a") str.capitalize() .upto('C’) .to_a() .join(', ') #=>
R.String #=> ’A, B, C'
str = R("a") str.capitalize() .upto('C’) .to_a() .join(', ') .ljust(10,
‘-’) #=> R.String #=> ’A, B, C---'
str = R("a") str.capitalize() .upto('C’) .to_a() .join(', ') .ljust(10,
‘-’) .to_native(); #=> string #=> ’A, B, C---'
RubyJS objects are wrappers Around naMve JS objects
Wrapper class RubyJS.Fixnum @include RubyJS.Comparable constructor: (__native__) ->
@__native__ = __native__; #=> new R.Fixnum(2)
Wrapper class RubyJS.Fixnum @include RubyJS.Comparable constructor: (@__native__) ->
odd: -> @__native__ % 2 != 0
Wrapper class RubyJS.Fixnum @include RubyJS.Comparable constructor: (@__native__) ->
odd: -> @__native__ % 2 != 0 next: -> new R.Fixnum(@__native__ + 1)
PorMng Ruby Code to JS
Ruby arr = %w(looks feels acts) arr.map {|w|
w.capitalize } .join(", ") .concat(" like Ruby") .center(35, '-') '---Looks, Feels, Acts like Ruby---’
RubyJS arr = R.w('looks feels acts')
RubyJS arr = R.w('looks feels acts') arr.map
{|w| w.capitalize }
RubyJS arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() )
RubyJS arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() ) .join(", ") .concat(" like Ruby") .center(35, '-') '---Looks, Feels, Acts like Ruby---’
Ruby arr = %w(looks feels acts) arr.map
{|w| w.capitalize } .join(", ") .concat(" like Ruby") .center(35, '-’) '---Looks, Feels, Acts like Ruby---’
RubyJS arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() ) .join(", ") .concat(" like Ruby") .center(35, '-') '---Looks, Feels, Acts like Ruby---’
Symbol#to_proc arr = R.w('looks feels acts') arr.map(
R.proc('capitalize’) ) .join(", ") .concat(" like Ruby") .center(35, '-')
Symbol#to_proc arr = R.w('looks feels acts') arr.map(
R.proc(’ljust’, 35) ) .join(", ") .concat(" like Ruby") .center(35, '-')
But I can do with library x, y ,z
arr = ['looks', 'feels', 'acts']; str = _.map(arr, (w)
-> S(w).capitalize().s; ).join(', ') str += ' like Ruby’; S(str).pad(15, '-');
RubyJS arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() ) .join(", ") .concat(" like Ruby") .center(35, '-') '---Looks, Feels, Acts like Ruby---’
Benefits
One dependency <script src="/es5shims.js"/> <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 dependency <script src="/es5shims.js"/> <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"/> <script src="/ruby.js">
One API _.map([], (w) -> ) _.chain(arr).(...).value() S("foo").capitalize().s
moment().format('L')
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”)
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
One chain arr = R.w('looks feels acts') arr.map((w)
-> w.capitalize() ) .join(", ") .concat(" like Ruby") .center(35, '-')
One documentaMon
One documentaMon
20 kbytes minified and gzipped
It scales
Dual-‐license • AGPL • Commercial license
Booh
Booh
Should I open source it?
None
DO IT
RubyJS is now MIT License
Happy hacking
Roadmap • Move from CoffeeScript to JavaScript •
RubyJS corelib – Time, Hash, Date • RubyJS corelib-‐lite – remove some rubyisms – simplify
RubyJS.org twi5er.com/hasclass