techdays - ironruby
Post on 15-May-2015
1.509 Views
Preview:
DESCRIPTION
TRANSCRIPT
IronRuby – A brave new world for .Net@Ben_Hall, Developer\tester, 7digital.comBen@BenHall.me.uk Blog.BenHall.me.uk CodeBetter.com/blogs/BenHall
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
Agenda
• Ruby• IronRuby• DLR• Merging IronRuby and C#
What is Ruby?
Why?
Right language for the right job
Everything is an object
“Hello World”.upcase
[5,3,4,1,6].sort
10.times { |i| puts “Loop count: #{i}” }
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
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’]
Natural Programming
x = [1,2,3]y = [4,5,6]
>>> x + y => [1,2,3,4,5,6]
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/
Duck Typing
class Queue def send(message) @server.open @server.issue(message) @server.close endend
Duck Typing
class SmtpService def send(message) @service.post(message) endend
Duck Typing
m = Message.newm.subject = “Hello TechDays!”q = Queue.news = SmtpService.newm.publish(q)m.publish(s)
Duck Typing
class Postman def send(message) phone_number = 012398622 @john.call(phone_number) endend
m.publish(Postman.new)
Mixins
class ProductPage < CMS::BasePage
include Editable include Themeable
include DroppableCustomisations
end
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
Blended of multiple languages
“Ruby is simple in appearance, but is very complex inside, just like our human body”
Yukihiro “matz” Matsumoto – Creator of Ruby
“trying to make Ruby natural, not simple”
Yukihiro “matz” Matsumoto – Creator of Ruby
If that’s
Ruby
http://www.flickr.com/photos/bflv/3328427869/
What’s IronRuby?
Static language => Dynamic language
http://github.com/BenHall/IronRuby_CSharp_Type_Interop
Ruby Frameworks - Exposing NHibernate domain model in a ‘RESTful’ way
http://github.com/BenHall/IronRestfulRails
@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
Ruby Frameworks - erb
http://github.com/BenHall/IronRuby_Erb_Templating
C# Frameworks - WPF
C# Frameworks - MeerPush
http://github.com/BenHall/MeerPush
What is the DLR?
http://www.flickr.com/photos/lastrounds/3199561205/sizes/o/
IronRuby
DLR
CLR
IronPython ?
http://www.flickr.com/photos/mendhak/2117622450/sizes/o/
Combing the two
worlds
Embedding IronRuby into C#
http://github.com/BenHall/EmbeddedIronRuby
Extending C# applications using Ruby and MEF
http://github.com/BenHall/ExtendViaMEF
Data Gen Screenshot
Reflector Screenshot
Resolver Systems
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
Testing C# applications
http://github.com/BenHall/wipflash_cucumber_driven_example
Ruby Everywhere!
change
How will the DLR
your world?
@Ben_HallBen@BenHall.me.ukBlog.BenHall.me.uk
http://lolcatgenerator.com/lolcat/120/
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.
top related