RubyMotion

RubyMotion ist ein kommerzielles Produkt, mit dem es möglich ist, native iOS Anwendungen in Ruby zu schreiben. Zur Zeit gibt es RubyMotion zu einem Einführungspreis. Inklusive MwSt. kostet es zur Zeit ca. 150 Euro.

Die Leute von Pragmatic Programmers haben ein kostenloses Video veröffentlicht, in dem zu sehen ist, wie man seine ersten Schritte mit RubyMotion tun kann.

Das besondere an RubyMotion ist, dass man im Gegensatz zu Projekten wie  Rhodes, wo ebenfalls in Ruby programmiert wird, vollen Zugriff auf die gesamte iOS API hat.

Ich habe mir also die Tage RubyMotion gekauft. Dabei stolperte ich gleich über die unterschiedlichsten Dinge:

Mac OS X Version: RubyMotion unterstützt Mac OS X ab Version 10.6 Snow Leopard. Allerdings wird 10.7 Lion empfohlen. Da ich noch auf Snow Leopard war, dachte ich, dass es ja eigentlich funktionieren müsste. Das tut es auch. Allerdings stößt man gleich auf die nächste Einschränkung.

XCode Version: Die letzte für Snow Leopard verfügbare XCode Version ist XCode 4.2. Damit lassen sich allerdings keine Apps mehr für iOS 5.1 und höher entwickeln. XCode 4.3.2 ist im App-Store nur noch für Mac OS X 10.7 Lion verfügbar.

Nun gut. Erste Versuche kann man sicherlich mit Snow Leopard auch machen. Allerdings stellte ich sehr schnell fest, dass es doch zu haken scheint. So passierte mir mehrfach folgendes:

Ich starte im Terminal das rake Kommando an, um die App zu bauen und den iPhone-Simulator zu starten. Bricht man dann via ctrl-c das rake Komando ab, so scheint das Terminal eingefroren zu sein. Vielmehr muss man den iPhone-Simulator zunächst beenden.

Also war nun der Punkt gekommen, trotz der möglichen Probleme unter Lion auf Lion zu wechseln. Doch davon will ich an anderer Stelle berichten.

I’ve updated my tests of external webpages using cucumber. If you like to test the amount of results of the google search we tested last time you can get the content of a special tag on the result of the query using the following step

Then /^I should get more than (\d+) results$/ do |arg1|
  page.find('#resultStats').text.sub('.', '').scan(/\d+/)[0].to_i.should be > arg1.to_i
end

See the files on github

I also prepared the cucumber steps for using the ruby debugger if something goes wrong.

Here you have use the ruby gem ruby-debug19 and start the debugger in the step with the debugger command. First you have to require the gem in env.rb

require 'ruby-debug'

See the files on github

 

Bildschirmfoto 2011-08-13 um 20.09.46

Über die von mir beschriebene vorhin beschriebene App zine, die eine Art personalisierte social media Suchmaschine ist, habe ich einen schönen Screencast zum Thema Testen von Ruby-Anwendungen mit Rspec gefunden, der Bestandteil einer ganzen Serie von Beiträgen zum Thema Ruby for Newbies ist.

Andrew Burgess zeigt dort, wie man sukzessive die Funktionalität einer Class erweitert, indem man zunächst einen fehlschlagenden Test erstellt und diesen dann durch den passenden Code erfolgreich durchlaufen lässt.

Er kann selbstverständlich in den gut 30 Minuten, die dieser Screencast dauert, nicht in alle Einzelheit gehen. Man erhält aber doch schon einen Überblick darüber, wohin die Reise geht.

 

Yesterday I came across a screencast by David Brady about how to generate hashes in ruby (and how you shouldn’t do it ;-) ). It’s very interesting for beginngers and intermediates to ruby. I put the video in here:

Ruby Hashes from David Brady on Vimeo.

James Edward Grey II saw this screencast and had same annotations so both did a video chat where JEG2 showed some really hard stuff about ruby hashes. So I had to sat back, stop the video everytime something new to me was shown and I was asking google or my ruby documentation about. But watching this second screencast opened up another wordl of ruby to me.

Associative Arrays with James Edward Gray II from David Brady on Vimeo.

netbeans-logo

Thomas Enebo möchte den Ruby Support von Netbeans, der ja kürzlich eingestellt wurde, wieder aufleben lassen. Er beschreibt, warum es wichtig ist, dass Netbeans als eine der wichtigen Java IDEs auch Ruby unterstützt. Dies ist ein einfacher Weg für Java Entwickler, sich mit der Programmiersprache Ruby zu befassen.

Er fordert dazu unter anderem, dass Netbeans (auch) auf github.com gehostet wird, da dies die zentrale Anlaufstelle für alle Ruby-Entwickler ist. Außerdem muss der Build-Prozess leichter werden. Dies soll durch eine Verschlankung erreicht werden, so dass man nur noch die notwendigen Teile herunterladen und übersetzten muss.

Wollen wir dem Projekt die Daumen drücken!

Once again I started coding some ruby code using TextMate. But now I installed Ruby 1.9.2 using rvm. As I did some month ago I wanted to use TextMate’s ctrl-h to show the ri info for a method or so.

So I installed the latest version of rdoc and rdoc-data. I generated the textmate wrapper as shown here. But this won’t work because running

rdoc-data –install

results in an error message:

~/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/fileutils.rb:121:in `chdir’: No such file or directory – ~/.rvm/gems/ruby-1.9.2-p0@test/gems/rdoc-data-2.5.3/data/1.9.2 (Errno::ENOENT)

And that’s correct because rdoc-data does not yet support ruby 1.9.2 as you can read here.

So I copied ~/.rvm/gems/ruby-1.9.2-p0@test/gems/rdoc-data-2.5.3/data/1.9.1 to ~/.rvm/gems/ruby-1.9.2-p0@test/gems/rdoc-data-2.5.3/data/1.9.2 hoping that the differences between 1.9.1 and 1.9.2 won’t matter.

Updating the textmate wrapper

rvm wrapper 1.9.2@mygemset textmate

and everything’s just fine.

Even after installing the current version of rdoc in a different gemset everything works just fine. Very strange because I thought the latest version of rdoc was the problem …

Using the Ruby-Bundle of TextMate let you ask the ruby built-in documentation of a command by hitting ctrl-h.

But I ran into some troubles when using rvm. I did’t get the manual for the method I asked for.

The problem seems to be the current version of rdoc as I found here. So I had to downgrade my rdoc gem from version 2.5.9 downto 2.4.3. But that sounds easier than it was for me. Every time I ran gem uninstall rdoc it wasn’t uninstalled. It stayed there. Even if I installed the older version and uninstalled version 2.5.9 rdoc –version brought up 2.5.9.

So I uninstalled my ruby using rvm uninstall 1.8.7 and removed also manually all gems connected with this ruby version in the following directories:

  • ~/.rvm/gemsets/ruby/1.8.7/
  • ~/.rvm/gems

Then I remove rdoc from the files

  • ~/.rvm/gemsets/global.gems
  • ~/.rvm/gemsets/default.gems

Installing ruby 1.8.7 again in rvm with the command rvm install 1.8.7 brought back the ruby version but without the latest rdoc. This one I could reinstall with gem install rdoc –version 2.4.3.

Now TextMate shows the correct help file.

Please see also the update.

Recently I found ruby-koans on github. If I should discribe it in a few words I would say it’s a test driven ruby tutorial.

After downloading ruby-koans you call rake and you see the first failing test.

Thinking AboutAsserts
test_assert_truth has damaged your karma.You have not yet reached enlightenment …
<false> is not true.

Please meditate on the following code:
./about_asserts.rb:10:in `test_assert_truth’
path_to_enlightenment.rb:29

Then you take a look at the test-file


# We shall contemplate truth by testing reality, via asserts.
def test_assert_truth
assert false                # This should be true
end# Enlightenment may be more easily achieved with appropriate
# messages.
def test_assert_with_message
assert false, “This should be true — Please fix this”
end

# To understand reality, we must compare our expectations against
# reality.
def test_assert_equality
expected_value = __
actual_value = 1 + 1

assert expected_value == actual_value
end

By correcting the tests you learn much about ruby and tests – step by step.

Like meta programming in ruby this is a meta-way in learning ruby.

Stefano Mancini has started several posts about design patterns in ruby. You can find the introduction to this series here. Stefano will publish the source code of his examples on github.

The first part of the series is about factories.  Stefano introduces factories as followed:

“An abstract Factory provides a common interface for creating families of related objects together.
The client object does not bother to build objects directly, but it calls the methods provided by this common interface.”

© 2012 JerryWho Suffusion theme by Sayontan Sinha