<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://gaurav-scr.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fgaurav-scr.spaces.live.com%2fcategory%2fRuby%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Blog on Rails: Ruby</title><description /><link>http://gaurav-scr.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catRuby</link><language>en-US</language><pubDate>Mon, 18 Aug 2008 01:46:44 GMT</pubDate><lastBuildDate>Mon, 18 Aug 2008 01:46:44 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://gaurav-scr.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>5269363790095024524</live:id><live:alias>gaurav-scr</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>Internet Explorer Worst?</title><link>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!180.entry</link><description>Here is something I found while scanning ruby source code:&lt;br&gt;&lt;br&gt;&amp;quot;Internet Explorer is the worst piece of crap to have ever been written, with the possible exception of Windows itself&amp;quot;&lt;br&gt;&lt;br&gt;It was written as a string in the following files:&lt;br&gt;&lt;br&gt;ruby\1.8\rexml\cdata.rb&lt;br&gt;ruby\1.8\rexml\comment.rb&lt;br&gt;ruby\1.8\rexml\doctype.rb&lt;br&gt;ruby\1.8\rexml\document.rb&lt;br&gt;ruby\1.8\rexml\element.rb&lt;br&gt;&lt;br&gt;I know internet explorer is not as good as firefox, but c'mon its not that bad. Is it?&lt;br&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=5269363790095024524&amp;page=RSS%3a+Internet+Explorer+Worst%3f&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=gaurav-scr.spaces.live.com&amp;amp;GT1=gaurav-scr"&gt;</description><comments>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!180.entry#comment</comments><guid isPermaLink="true">http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!180.entry</guid><pubDate>Mon, 21 May 2007 10:34:05 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://gaurav-scr.spaces.live.com/blog/cns!49208A72E4EB818C!180/comments/feed.rss</wfw:commentRss><wfw:comment>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!180.entry#comment</wfw:comment><dcterms:modified>2007-05-21T10:34:05Z</dcterms:modified></item><item><title>Automating Powerpoint with ruby</title><link>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!173.entry</link><description>We know that ruby is a language of few words.&lt;br&gt;We can express a lot of things in a few words.&lt;br&gt;&lt;br&gt;I was trying to export few slides in my powerpoint presentation to an image format using ruby.&lt;br&gt;I could not find any documentation for it anywhere except for a few basic things. But when I tried it by hit and trial I found out it to be surprisingly easy. It required just a few lines.&lt;br&gt;&lt;br&gt;Here is what you have to do&lt;br&gt;&lt;br&gt;&lt;span style="color:rgb(255, 0, 0)"&gt;----------------------------------------------------------------------&lt;/span&gt;&lt;br&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;require 'win32ole'&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;begin&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  #  open powerpoint&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  ppt = WIN32OLE.new('Powerpoint.Application')&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  #  ensure it is visible&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  ppt.Visible = true&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  #  open the presentation to be exported&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  pre = ppt.Presentations.Open(&amp;quot;d:\\1.pptx&amp;quot;)&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  #  export the file&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  pre.Slides(1).Export(&amp;quot;d:\\exp_file.png&amp;quot;,&amp;quot;png&amp;quot;)&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;rescue&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;ensure&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  #  close powerpoint, will close all the currently open files&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;  ppt.Quit()&lt;/span&gt;&lt;br style="color:rgb(0, 0, 255)"&gt;&lt;span style="color:rgb(0, 0, 255)"&gt;end&lt;/span&gt;&lt;br&gt;&lt;span style="color:rgb(255, 0, 0)"&gt;----------------------------------------------------------------------&lt;/span&gt;&lt;br&gt;&lt;br&gt;Thats it. It is a full blown application. You can always use rmagick to further process this exported image.&lt;br&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=5269363790095024524&amp;page=RSS%3a+Automating+Powerpoint+with+ruby&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=gaurav-scr.spaces.live.com&amp;amp;GT1=gaurav-scr"&gt;</description><comments>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!173.entry#comment</comments><guid isPermaLink="true">http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!173.entry</guid><pubDate>Fri, 23 Mar 2007 10:49:36 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://gaurav-scr.spaces.live.com/blog/cns!49208A72E4EB818C!173/comments/feed.rss</wfw:commentRss><wfw:comment>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!173.entry#comment</wfw:comment><dcterms:modified>2007-03-23T10:58:09Z</dcterms:modified></item><item><title>Creating a User Interface in ruby ( Ruby playing nice with xaml )</title><link>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!171.entry</link><description>&lt;div&gt;There is a great gem 'rubyclr' that allows ruby to use .net code ie clr.&lt;/div&gt;
&lt;div&gt;This gem can be installed with the command &amp;quot;gem install rubyclr&amp;quot;.&lt;/div&gt;
&lt;div&gt;&lt;br&gt;Here I am going to present an example using that gem. It will be a simple application that will show how to trap xaml events using ruby.&lt;br&gt;So first you have to install the gem.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Then we will prepare the xaml file.&lt;br&gt;Its content would be:&lt;br&gt;&lt;font color="#ff0000"&gt;--------------------------------------------------------------------------------------&lt;/font&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;&amp;lt;Window&lt;br&gt; xmlns=&amp;quot;&lt;/font&gt;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;&lt;font color="#0000ff"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/font&gt;&lt;/a&gt;&lt;font color="#0000ff"&gt;&amp;quot;&lt;br&gt; xmlns:x=&amp;quot;&lt;/font&gt;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;&lt;font color="#0000ff"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/font&gt;&lt;/a&gt;&lt;font color="#0000ff"&gt;&amp;quot;&amp;gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff"&gt; &amp;lt;Grid x:Name=&amp;quot;LayoutRoot&amp;quot;&amp;gt;&lt;br&gt;  &amp;lt;Button Margin=&amp;quot;8,0,8,5.723&amp;quot; VerticalAlignment=&amp;quot;Bottom&amp;quot; Content=&amp;quot;Button&amp;quot; Name=&amp;quot;the_button&amp;quot;/&amp;gt;&lt;br&gt;  &amp;lt;TextBox Margin=&amp;quot;8,8,8,38&amp;quot; Name=&amp;quot;the_text_box&amp;quot;/&amp;gt;&lt;br&gt; &amp;lt;/Grid&amp;gt;&lt;br&gt;&amp;lt;/Window&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;font color="#ff0000"&gt;--------------------------------------------------------------------------------------&lt;/font&gt;&lt;br&gt;save this file as first.xaml&lt;br&gt;Note that we hve given names to both the controls as we will be using these names in our ruby code.&lt;/div&gt;
&lt;div&gt;You can use notepad to mage this file or you can use microsoft blend which can allow to to may more fancy things.&lt;br&gt;There is a trial available for download. Its size is about 25 MB. For simple projects you can always use notepad.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Now we will create a ruby file to handle the events.&lt;br&gt;Its content would be:&lt;br&gt;&lt;font color="#ff0000"&gt;--------------------------------------------------------------------------------------&lt;/font&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;#  load the libraries&lt;br&gt;require 'rubygems'&lt;br&gt;require 'wpf'&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff"&gt;#  load the xaml file&lt;br&gt;window = XamlReader.Load(System::IO::File.open_read('first.xaml'))&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;br&gt;&lt;font color="#0000ff"&gt;#  get the controls&lt;br&gt;button = window.find_name('the_button')&lt;br&gt;txt_box = window.find_name('the_text_box')&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff"&gt;#  trap the mouse enter event&lt;br&gt;button.mouse_enter do |sender, args|&lt;br&gt;  txt_box.text += &amp;quot;MOUSE ENTERED\n&amp;quot;&lt;br&gt;end&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff"&gt;#  trap the mouse leave event&lt;br&gt;button.mouse_leave do |sender, args|&lt;br&gt;  txt_box.text += &amp;quot;MOUSE LEFT\n&amp;quot;&lt;br&gt;end&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff"&gt;#  trap the mouse click event&lt;br&gt;button.click do |sender, args|&lt;br&gt;  txt_box.text += &amp;quot;MOUSE CLICKED\n&amp;quot;&lt;br&gt;end&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font color="#0000ff"&gt;#  run the application (most important)&lt;br&gt;Application.new.run(window)&lt;br&gt;&lt;/font&gt;&lt;font color="#ff0000"&gt;--------------------------------------------------------------------------------------&lt;/font&gt;&lt;br&gt;save this file as first.rb&lt;/div&gt;
&lt;div&gt;As you can see this file is preety much self descriptive. We just require the libraries, get the controls and handle the events.&lt;/div&gt;
&lt;div&gt;&lt;br&gt;Thats all to it. Just compile the ruby file using the command &amp;quot;ruby first.rb&amp;quot;. Or if you dont you want the ugly dos window in the background you can use the command &amp;quot;rubyw first.rb&amp;quot;&lt;/div&gt;
&lt;div&gt;Isnt that simple!&lt;br&gt;&lt;/div&gt;&lt;div&gt;&lt;table cellspacing="0" border="0"&gt;&lt;tr height="8"&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign="top"&gt;&lt;p&gt;&lt;a href="http://blufiles.storage.live.com&amp;#47;y1p6tyMtNRm_aTjDxu3yIzXYI6ZBlYcR3Cf7LGKJDSIHxtwrca2c7_M5_ZucMSV41ye"&gt;&lt;img src="http://storage.live.com&amp;#47;items&amp;#47;49208A72E4EB818C&amp;#33;172&amp;#58;thumbnail" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/td&gt;&lt;td width="15"&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=5269363790095024524&amp;page=RSS%3a+Creating+a+User+Interface+in+ruby+(+Ruby+playing+nice+with+xaml+)&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=gaurav-scr.spaces.live.com&amp;amp;GT1=gaurav-scr"&gt;</description><comments>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!171.entry#comment</comments><guid isPermaLink="true">http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!171.entry</guid><pubDate>Thu, 22 Mar 2007 11:35:19 GMT</pubDate><slash:comments>2</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://gaurav-scr.spaces.live.com/blog/cns!49208A72E4EB818C!171/comments/feed.rss</wfw:commentRss><wfw:comment>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!171.entry#comment</wfw:comment><dcterms:modified>2007-03-23T06:16:11Z</dcterms:modified></item><item><title>Finding classes dynamically in RUBY</title><link>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!152.entry</link><description>&lt;div&gt;Here is an update to this code making it even  easier to find classes methods on the runtime.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;class Called&lt;br&gt; def called_method&lt;br&gt;  &amp;quot;string output&amp;quot;&lt;br&gt; end&lt;br&gt;end&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;class.rb&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;
&lt;div&gt;class Test&lt;br&gt;  def calltest(clsname,methodname)&lt;br&gt;    require clsname.downcase&lt;br&gt;    puts eval(clsname.capitalize).new.method(methodname).call&lt;br&gt;  end&lt;br&gt;end&lt;/div&gt;
&lt;div&gt;Test.new.calltest('called','called_method')&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;caller.rb&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;ths output obviously is: string output&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Awesome isn't it.&lt;/div&gt;
&lt;div&gt;There are some restrictions link the class name must be same as the file name but still it does the job.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; 
&lt;hr&gt;
&lt;/div&gt;
&lt;div&gt;&lt;strong&gt; Older code&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Today while writing a piece of code I needed to find a class by name. I haven't seen it in any other languages that I have programmed in but then if its ruby it might be possible.&lt;/div&gt;
&lt;div&gt;Well its not only possible but really easy to implement.&lt;/div&gt;
&lt;div&gt;Just look at the following piece of code.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#ffffff" face="Garamond, Times, Serif" size=2&gt;class ClassName&lt;br&gt; def func&lt;br&gt;  puts &amp;quot;I am output&amp;quot;&lt;br&gt; end&lt;br&gt;end&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#ffffff" face="Garamond, Times, Serif" size=2&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font style="background-color:#ffffff" face="Garamond, Times, Serif" size=2&gt;classname = 'ClassName'&lt;br&gt;cls = Kernel.const_get(classname)&lt;br&gt;obj = cls.new&lt;br&gt;obj.method(&amp;quot;func&amp;quot;).call&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;This example first finds a class then its method and in the last line executes it.&lt;/div&gt;
&lt;div&gt;Really smooth isnt it.&lt;/div&gt;&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=5269363790095024524&amp;page=RSS%3a+Finding+classes+dynamically+in+RUBY&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=gaurav-scr.spaces.live.com&amp;amp;GT1=gaurav-scr"&gt;</description><comments>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!152.entry#comment</comments><guid isPermaLink="true">http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!152.entry</guid><pubDate>Fri, 15 Sep 2006 17:50:54 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://gaurav-scr.spaces.live.com/blog/cns!49208A72E4EB818C!152/comments/feed.rss</wfw:commentRss><wfw:comment>http://gaurav-scr.spaces.live.com/Blog/cns!49208A72E4EB818C!152.entry#comment</wfw:comment><dcterms:modified>2006-09-18T06:58:08Z</dcterms:modified></item></channel></rss>