RSS

カテゴリー別アーカイブ: IronRuby

Using the DLL you wrote.

 

require "System"
require "c:\\bin\\Cui.dll"

app = Cui::Application.new
app.clear()
main = app.topWindow

Cui::Color.bgColor = 0
main.fill(‘ ‘)
Cui::Color.fgColor = 15
Cui::Color.bgColor = 8
main.drawLine(0, "Cui Test", 1)

System::Console.ReadKey()
System::Console.ResetColor()
System::Console.WriteLine("Done.")
app.clear()

 
コメントする

投稿者: : 2011/10/20 投稿先 IronRuby

 

Using System.Data.SqlClient

 

# coding: SJIS
require "System.Data"
include System::IO
include System::Text
include System::Data
include System::Data::SqlClient

con = System::Console
sql = "SELECT * FROM dbo.test1"
conn1 = SqlConnection.new
conn1.ConnectionString = ‘Data Source=.\SQLEXPRESS; Integrated Security=True; Initial Catalog=test’
conn1.Open
adapter1 = SqlDataAdapter.new(sql, conn1)
dataSet1 = DataSet.new
adapter1.Fill(dataSet1)
rs = dataSet1.Tables[0]
rs.Rows.each do |row|
  con.WriteLine(row[0].ToString() + ", " + row[1].ToString())
end
conn1.Close

 
コメントする

投稿者: : 2011/10/20 投稿先 IronRuby

 

Adding / Overriding methods to an object

 

obj = System::Object.new

class << obj
def ToString()
return “an object”
end

def Hello()
puts “Hello”
end
end

puts obj.ToString()
obj.Hello()

 
コメントする

投稿者: : 2011/10/19 投稿先 IronRuby

 

Internal class

 

# class test

class Class1

  class Class2
    def initialize()
      @name = ‘Class2’
    end
    attr_accessor :name
  end

  def initialize()
    @name = ‘Class1’
  end

  attr_accessor :name

end # Class1

obj = Class1.new
puts obj.name

obj2 = Class1::Class2.new
puts obj2.name

 
コメントする

投稿者: : 2011/10/19 投稿先 IronRuby

 

System.Console and color text sample

 

# Console Test
require "System"

class ConsoleColor
    Black = 0
    DarkBlue = 1
    DarkGreen = 2
    DarkCyan = 3
    DarkRed = 4
    DarkMagenta = 5
    DarkYellow = 6
    DarkGray = 7
    Gray = 8
    Blue = 9
    Green = 10
    Cyan = 11
    Red = 12
    Magenta = 13
    Yellow = 14
    White = 15
end

con = System::Console
con.ForegroundColor = ConsoleColor::Blue
con.WriteLine("**** Console class test ****")
con.ForegroundColor = ConsoleColor::Black
con.BackgroundColor = ConsoleColor::Gray
con.WriteLine("**** Console class test ****")
con.ForegroundColor = ConsoleColor::White
con.BackgroundColor = ConsoleColor::Black

 
コメントする

投稿者: : 2011/10/19 投稿先 IronRuby

 

Enum files by System.IO.Directory

 

# coding: SJIS

include System::IO

if $*.size == 0 then
  abort "Usage: ir ir_enum_file.rb directory"
else
  dir = $*[0]
end

Directory.EnumerateFiles(dir).each do |f|
  puts f
end

 
コメントする

投稿者: : 2011/10/19 投稿先 IronRuby

 

System.IO.BinaryReader in IronRuby

 

 

# coding: SJIS
include System::IO
include System::Text

if $*.size == 0 then
  puts "Usage: ir ir_binary_reader.rb path [text]"
  exit(9)
else
  path = $*[0]
end

reader = BinaryReader.new(FileStream.new(path, FileMode.Open))
buffer = System::Array[System::Byte].new(1024)
n = reader.Read(buffer, 0, buffer.Length)
reader.Close()
puts "length = " + n.to_s

if $*.size == 2 then
  utf8 = UTF8Encoding.new
  s = utf8.GetString(buffer, 0, n)
  System::Console.Write(s)
else
  for i in 1..n do
    puts sprintf("%02x", buffer[i-1])
  end
end

puts "Done."

 
コメントする

投稿者: : 2011/10/19 投稿先 IronRuby