Success! Thanks Eloy. Matt
On Oct 6, 2010, at 11:06 AM, Eloy Duran wrote: > Aha, I see. Well, first let me say that, as you noticed, the internals > of IRB are indeed different than the one from MRI. This is a rewrite > of IRB called DietRB http://github.com/alloy/dietrb, which was > mentioned in the changelog, but not the announcement. I haven’t worked > on completing the API and no documentation yet, but that will happen > before the MacRuby 0.8 release. In the meantime, I will release new > gem versions https://rubygems.org/gems/dietrb, and please do file > tickets on the MacRuby Trac or github issues page! > > On to the problem at hand, I won’t support this use in DietRB, because > it’s not a proper API anyways. Please try the following, in your > .irbrc: > > require "rubygems" > require "ap" > > if IRB.version.include?('DietRB') > # MacRuby code > class AwesomePrintFormatter < IRB::Formatter > def inspect_object(object) > object.awesome_inspect > end > end > IRB.formatter = AwesomePrintFormatter.new > else > # MRI code > end > > Regarding the way to differentiate between two implementations. I > think checking if an object responds to a method is the way to go, if > you are going to call that method. In this case, maybe some day you'll > require a gem which defines a Kernel#framework method, breaking your > condition. So for these kinds of things I generally use: if > defined?(MACRUBY_VERSION), or in this case you can differentiate with > the IRB.version string, meaning that if you would install the DietRB > gem on MRI 1.9, it would keep working. > > Thanks for the report! > > Cheers, > Eloy > > On Wed, Oct 6, 2010 at 6:25 PM, Matt Massicotte <massico...@apple.com> wrote: >> I wasn't clear at all, sorry. I can't get *automatic* formatting to work. >> My .irbrc file looks like this: >> require "rubygems" >> require "ap" >> >> unless Kernel.respond_to?(:framework) #admitted ugly hack >> require 'irb/completion' >> >> IRB::Irb.class_eval do >> def output_value >> ap @context.last_value >> end >> end >> >> end >> This makes the default irb formatting us awesome_print. I got this from the >> awesome_print github page. If I move the class_eval statement out of the >> conditional, I get this: >> matt$ macirb >> /Users/matt/.irbrc:1:in `<main>': uninitialized constant IRB::Irb >> (NameError) >> from /usr/local/bin/macirb:13:in `block' >> from /usr/local/bin/macirb:9:in `block' >> from /usr/local/bin/macirb:3:in `<main>' >> As an aside: >> I have a ton of code that needs to run under both macruby and rubycocoa. >> Due to the ObjC calling conventions and OSX module stuff, portability is >> kind of a pain. I use the Kernel.respond_to?(:framework) construct often, >> but I welcome better suggestions. >> Matt >> On Oct 6, 2010, at 9:02 AM, Eloy Duran wrote: >> >> I did, in the email that you replied on. Could you please send some more >> info about what really happens? >> Eloy >> >> On Oct 6, 2010, at 5:49 PM, Matt Massicotte wrote: >> >> I didn't know about awesome_print, and it's kind of blown my mind. The >> default irb formatting is great. Only, I cannot get it to work in macirb. >> It looks like the internals of IRB is completely different. >> Has anyone had an luck with this? >> Matt >> On Oct 6, 2010, at 2:10 AM, Eloy Duran wrote: >> >> I verified that it does work: >> sudo macgem install awesome_print >> Password: >> unknown: warning: ignoring alias >> Successfully installed awesome_print-0.2.1 >> 1 gem installed >> % cat ~/.irbrc >> require 'rubygems' >> require 'ap' >> % macirb >> irb(main):001:0> data = [ false, 42, %w(forty two), { :now => Time.now, >> :class => Time.now.class, :distance => 42e42 } ] >> => [false, 42, ["forty", "two"], {:now=>2010-10-06 11:06:37 +0200, >> :class=>Time, :distance=>4.2e+43}] >> irb(main):002:0> ap data >> [ >> [0] false, >> [1] 42, >> [2] [ >> [0] "forty", >> [1] "two" >> ], >> [3] { >> :now => 2010-10-06 11:06:37 +0200, >> :class => Time < NSDate, >> :distance => 4.2e+43 >> } >> ] >> => nil >> It’s probably, as Joshua has said, being installed with the wrong rubygems >> installation. >> Eloy >> On Oct 6, 2010, at 8:38 AM, Joshua Ballanco wrote: >> >> Hi Brad, >> What's happening here is that the 'gem' command that ships with MacRuby is >> named 'macgem'. However, 'macirb' still looks at the same .irbrc file that >> the system 'irb' command does. So, if you've put in a require for >> awesome_print into your .irbrc, then 'macirb' will look for it but not find >> it. >> Try running 'macgem install awesome_print' instead and let us know how it >> goes. >> Cheers, >> Josh >> >> On Oct 5, 2010, at 10:29 PM, Brad Hutchins wrote: >> >> "DietRB" or "macirb" don't seem to be working after I install "gem >> awesome_print" >> I have to "gem uninstall awesome_print" to get it to work. >> I am guessing DietRB may be the name of the IRB but it is still launches >> with "macirb" >> >> >> localhost:Homebrew Brad$ rvm macruby >> >> localhost:Homebrew Brad$ macruby -v >> MacRuby 0.7 (ruby 1.9.2) [universal-darwin10.0, x86_64] >> localhost:Homebrew Brad$ DietRB >> -bash: DietRB: command not found >> >> localhost:Homebrew Brad$ macirb >> ap gem not found. Try typing 'gem install awesome_print' to get super-fancy >> output. >> irb(main):001:0> exit >> localhost:Homebrew Brad$ gem install awesome_print >> unknown: warning: ignoring alias >> Successfully installed awesome_print-0.2.1 >> 1 gem installed >> localhost:Homebrew Brad$ macirb >> /Users/Brad/.irbrc:1:in `<main>': uninitialized constant IRB::Irb >> (NameError) >> from /usr/local/bin/macirb:13:in `block' >> from /usr/local/bin/macirb:9:in `block' >> from /usr/local/bin/macirb:3:in `<main>' >> localhost:Homebrew Brad$ DietRB >> -bash: DietRB: command not found >> >> localhost:Homebrew Brad$ rvm list >> rvm rubies >> jruby-1.5.2 [ x86_64-java ] >> => macruby-0.7 [ x86_64 ] >> rbx-1.0.1-20100603 [ x86_64 ] >> ruby-1.8.7-p302 [ x86_64 ] >> ruby-1.9.2-p0 [ x86_64 ] >> >> localhost:Homebrew Brad$ gem uninstall awesome_print >> Successfully uninstalled awesome_print-0.2.1 >> localhost:Homebrew Brad$ macirb >> ap gem not found. Try typing 'gem install awesome_print' to get super-fancy >> output. >> irb(main):001:0> >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> >> _______________________________________________ >> MacRuby-devel mailing list >> MacRuby-devel@lists.macosforge.org >> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel >> >> > _______________________________________________ > MacRuby-devel mailing list > MacRuby-devel@lists.macosforge.org > http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel