Skip to content

Instantly share code, notes, and snippets.

@jschementi
jschementi / mssql_adapter.rb
Created April 22, 2009 21:02
IronRuby MSSQL adapter for System.Data.SqlClient
require 'active_record/connection_adapters/abstract_adapter'
require 'mscorlib'
require 'System.Data'
module System
class DBNull
def nil?
true
end
end
# The first load path contains rb files which load .NET based libraries,
# including the standard library and the .NET library
$:
# => ["c:/dev/ironruby/Merlin/Main/Languages/Ruby/libs/",
# "c:/ruby/lib/ruby/site_ruby/1.8/",
# "c:/ruby/lib/ruby/1.8/", "."]
# Special require which enables CLR interop
# (mscorlib.rb doesn't exist on the load path)
require 'mscorlib'
Processing PostsController#index (for 127.0.0.1 at 2009-05-06 00:39:41) [GET]
Rendering template within layouts/posts
Rendering posts/index
Completed in 460ms (View: 150, DB: 0) | 200 OK [http://localhost/posts]
Processing PostsController#new (for 127.0.0.1 at 2009-05-06 00:39:46) [GET]
Rendering template within layouts/posts
Rendering posts/new
Completed in 855ms (View: 672, DB: 0) | 200 OK [http://localhost/posts/new]
class CreatePeople < ActiveRecord::Migration
def self.up
create_table :people do |t|
t.string :first_name
t.string :last_name
t.integer :age
t.timestamps
end
end
irb(main):002:0> Person.all
=> [#<Person id: 1, first_name: "Foo", last_name: "Bar">]
irb(main):003:0> p = Person.first
=> #<Person id: 1, first_name: "Foo", last_name: "Bar">
irb(main):004:0> p.first_name = "Jimmy"
=> "Jimmy"
irb(main):005:0> p.last_name = "Schementi"
=> "Schementi"
irb(main):006:0> p.save
=> true
@jschementi
jschementi / sinatra-0.9.4.patch
Created May 14, 2009 23:44
Patch Sinatra 0.9.1.1 to work with IronRuby
--- a/sinatra-0.9.4/lib/sinatra/base.rb Tue Aug 18 21:10:44 2009
+++ b/sinatra-0.9.4/lib/sinatra/base.rb Tue Aug 18 22:52:03 2009
@@ -957,6 +957,14 @@
/active_support/, # active_support require hacks
] unless self.const_defined?('CALLERS_TO_IGNORE')
+ unless self.const_defined?('RUBY_IGNORE_CALLERS')
+ IRONRUBY_IGNORE_CALLERS = [
+ /\.cs/, # C# stack traces that shows up in debug mode
+ /$^/ # .NET stack traces that shows up in release mode are without the filename
--- a\ruby\lib\ruby\1.8\webrick\httprequest.rb Tue Feb 13 03:01:20 2007
+++ b\ruby\lib\ruby\1.8\webrick\httprequest.rb Thu May 7 16:45:54 2009
@@ -16,6 +16,11 @@
require 'webrick/httputils'
require 'webrick/cookie'
+# IronRuby bug: IO#read seems to chop off the first char
+
+class TCPSocket
+ def read size
TOPLEVEL_BINDING = binding unless defined?(TOPLEVEL_BINDING)
def repl(scope = TOPLEVEL_BINDING)
Repl.start(scope)
end
module Repl
def self.start(scope = TOPLEVEL_BINDING)
quitstr = ['quit', 'exit', '']
while true
begin
require 'Microsoft.Scripting, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
rescue
require 'Microsoft.Scripting, Version=2.0.5.0, Culture=neutral, PublicKeyToken=null'
end
include Microsoft::Scripting
include Microsoft::Scripting::Hosting
def python(str, type = :file)
@python_engine ||= DynamicApplication.Current.Runtime.
# Accessing named children
# ------------------------
# Normal WPF
window.find_name('message_box').text = "Hello"
# wpf.rb
window.message_box.text = "Hello"
# Hiding, Showing, Collapsing elements