TechDays - IronRuby

42
IronRuby – A brave new world for .Net @Ben_Hall, Developer\tester, 7digital.com [email protected] Blog.BenHall.me.uk CodeBetter.com/blogs/BenHall

description

Presentation of IronRuby given in Sweden at TechDays on 24th March 2010

Transcript of TechDays - IronRuby

Page 1: TechDays - IronRuby

IronRuby – A brave new world for .Net@Ben_Hall, Developer\tester, [email protected] Blog.BenHall.me.uk CodeBetter.com/blogs/BenHall

Page 2: TechDays - IronRuby

London (UK) based C# MVPWeb Developer @ 7digital.com

Working on a number of Open Source Projects

Co-Author of Testing ASP.net Web Applications

http://www.testingaspnet.com

Page 3: TechDays - IronRuby

Agenda

• Ruby• IronRuby• DLR• Merging IronRuby and C#

Page 4: TechDays - IronRuby

What is Ruby?

Page 5: TechDays - IronRuby

Why?

Page 6: TechDays - IronRuby

Right language for the right job

Page 7: TechDays - IronRuby

Everything is an object

“Hello World”.upcase

[5,3,4,1,6].sort

10.times { |i| puts “Loop count: #{i}” }

Page 8: TechDays - IronRuby

Blocks

10.times do |i| puts “Loop count: #{i}”

end

Loop count: 0Loop count: 1Loop count: 2Loop count: 3Loop count: 4Loop count: 5Loop count: 6Loop count: 7Loop count: 8Loop count: 9

Page 9: TechDays - IronRuby

Blocks

search_engines =   %W[Google Yahoo Bing].map do |engine|    "http://www.#{engine.downcase}.com"  end

search_engines = [ ‘http://www.google.com’, ‘http://www.yahoo.com’, ‘http://www.bing.com’]

Page 10: TechDays - IronRuby

Natural Programming

x = [1,2,3]y = [4,5,6]

>>> x + y => [1,2,3,4,5,6]

Page 11: TechDays - IronRuby

Duck Typing

# Message sends itself via some transport protocol

class Message def publish(transport) puts transport.send(self) endend

http://www.flickr.com/photos/normis/337183421/

Page 12: TechDays - IronRuby

Duck Typing

class Queue def send(message) @server.open @server.issue(message) @server.close endend

Page 13: TechDays - IronRuby

Duck Typing

class SmtpService def send(message) @service.post(message) endend

Page 14: TechDays - IronRuby

Duck Typing

m = Message.newm.subject = “Hello TechDays!”q = Queue.news = SmtpService.newm.publish(q)m.publish(s)

Page 15: TechDays - IronRuby

Duck Typing

class Postman def send(message) phone_number = 012398622 @john.call(phone_number) endend

m.publish(Postman.new)

Page 16: TechDays - IronRuby

Mixins

class ProductPage < CMS::BasePage

include Editable    include Themeable

include DroppableCustomisations

end

Page 17: TechDays - IronRuby

Extendable

class Fixnum def odd?() !even? end def even?() self % 2 == 0 endend

>>> 1.odd?

=> true>>>

1.even?=> false>>>

2.odd?=> false>>>

2.even?=> true

Page 18: TechDays - IronRuby

Blended of multiple languages

Page 19: TechDays - IronRuby

“Ruby is simple in appearance, but is very complex inside, just like our human body”

Yukihiro “matz” Matsumoto – Creator of Ruby

Page 20: TechDays - IronRuby

“trying to make Ruby natural, not simple”

Yukihiro “matz” Matsumoto – Creator of Ruby

Page 21: TechDays - IronRuby

If that’s

Ruby

http://www.flickr.com/photos/bflv/3328427869/

What’s IronRuby?

Page 22: TechDays - IronRuby

Static language => Dynamic language

http://github.com/BenHall/IronRuby_CSharp_Type_Interop

Page 23: TechDays - IronRuby

Ruby Frameworks - Exposing NHibernate domain model in a ‘RESTful’ way

http://github.com/BenHall/IronRestfulRails

Page 24: TechDays - IronRuby

@post = r.GetPost("PostID", params[:id].to_i)

class PostRepository def method_missing(m, *args) columnName = m.id2name.sub(/find_by_/, "") get_post columnName, *args endend

@post = r.find_by_PostID 1@post = r.find_by_Title “Post 1"http://github.com/BenHall/IronRestfulRails

Page 25: TechDays - IronRuby

Ruby Frameworks - erb

http://github.com/BenHall/IronRuby_Erb_Templating

Page 26: TechDays - IronRuby

C# Frameworks - WPF

Page 27: TechDays - IronRuby

C# Frameworks - MeerPush

http://github.com/BenHall/MeerPush

Page 28: TechDays - IronRuby

What is the DLR?

http://www.flickr.com/photos/lastrounds/3199561205/sizes/o/

Page 29: TechDays - IronRuby

IronRuby

DLR

CLR

IronPython ?

Page 30: TechDays - IronRuby

http://www.flickr.com/photos/mendhak/2117622450/sizes/o/

Combing the two

worlds

Page 31: TechDays - IronRuby

Embedding IronRuby into C#

http://github.com/BenHall/EmbeddedIronRuby

Page 32: TechDays - IronRuby

Extending C# applications using Ruby and MEF

http://github.com/BenHall/ExtendViaMEF

Page 33: TechDays - IronRuby

Data Gen Screenshot

Page 34: TechDays - IronRuby

Reflector Screenshot

Page 35: TechDays - IronRuby

Resolver Systems

Page 36: TechDays - IronRuby

C# 4.0 - dynamic

http://github.com/BenHall/IronRuby_CSharp_4

class Person def say_hello puts "Hello world from IronRuby!" endend

static void Main(string[] args) { Console.WriteLine("Executing from C#"); ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime(); ScriptScope scope = runtime.ExecuteFile("person.rb"); dynamic person = scope.Engine.Execute("Person.new"); person.say_hello();

Console.ReadLine(); }

Program.cs

person.rb

Page 37: TechDays - IronRuby

Testing C# applications

http://github.com/BenHall/wipflash_cucumber_driven_example

Page 38: TechDays - IronRuby

Ruby Everywhere!

Page 39: TechDays - IronRuby

change

How will the DLR

your world?

Page 40: TechDays - IronRuby

@[email protected]

http://lolcatgenerator.com/lolcat/120/

Page 41: TechDays - IronRuby

Utvärdera gärna sessionen.

Dina synpunkter är mycket värdefulla för oss. Därför är vi mycket tacksamma för att du tar dig någon minut att utvärdera den session som du just har lyssnat på. Besök din MINT-profil* i din mobil, gå till dina sessioner och klicka på ”utvärdera”.

In English: Your feedback is very valuable to us. Therefore, we are very grateful that you take a minute to evaluate the session that you just listened to.

Tack!*MINT är en mobil tjänst för evenemang och möten som bland annan erbjuder dig möjligheten att utvärdera de sessioner du besöker direkt i din mobil. Om du saknar mobil eller inte kan komma åt MINT av annan anledning har vi fysiska utvärderingar i pappersform.

Page 42: TechDays - IronRuby