views:

357

answers:

4

I need a set of ruby problems + solutions that require solutions involving more than a few interacting classes. The point is to teach OOP in ruby to a beginner. Sites like rubyquiz tend to have problems that require clever algorithms, rather than OOP design. The best I can think of so far is to do a very simple game like pong, but Ruby still feels sketchy on the UI-building front, so I was hoping to avoid the additional complications for now. That, and I don't want to spend the time writing solutions for the person I'm teaching to look at.

Please don't bother posting advice on how else to go about learning OOP - seen it in other questions already.

A: 

Try Wikibooks entry on Ruby - section introducing objects and so on. It's pretty clear for one with no knowledge in OOP.

Then you could continue with pickaxe book.

Good tasks to study porgramming within contemporary paradigms is to write some console-based apps with usage of external libraries. Try to write console app to emit a message to AOL or Jabber messenger (uses console input for message text and UIN and config file with json to store login & password for the network).

Or piechart generator - you input a set of numbers. The result in piechart, stored as a pdf file.

Or simple grep analog.

And so on...

kirushik
I'm looking for example problems, not explanations of OOP - there are plenty of sites that explain that better than your link. That, and in case it didn't come through, I'm a pretty experience programmer, teaching someone. So that someone already has a better resource than any tutorial out there (at least I hope so :) ).Thanks for the project ideas (though I think web communication is in the same boat as GUI programming - a complication I don't want to introduce just yet).
fakeleft
Oh, pardon me.I'm not native English speaker - so nuances are sometimes difficult for me to get from the first time.Will add another answer - with problems soon.
kirushik
+1  A: 

Go with your pong example. As for the GUI, just use Shooes by _why

You can see here in the the ShoeBox where graphical ruby apps are shared by the Shooes community.

jrhicks
Thanks. The only reservation I have about using shoes is that _why's killed his online presence, including his projects - is there a central place where the shoes community still takes care of the project (further development work, documentation, etc)? All I see is a bunch of repos on github, and now-obsolete articles about setting it up. I'm even having trouble finding a copy of "Nobody Knows Shoes" anymore.
fakeleft
http://github.com/shoes/shoes/downloads - includes binaries and nks.pdf
jrhicks
+1  A: 

Ok, here come problems for OOP.

  • Some client & server. CLI chat, for example. In Ruby, network interaction is simple. And yes, it is object-oriented.

Have a look:

  class TimeServer < GServer
    def serve(io)
      io.puts(Time.now.to_i)
    end
  end
server = TimeServer.new(10001)
server.start

It will serve seconds from 1970 for all the responses on port 10001. Connect and print result using

s = TCPSocket.open('localhost', 10001)
puts s.gets.chomp

And so on...

  • some data processing. F.e. you are given financial data of some people in yaml or json format, and empty fields in records are skipped. Convert db into sqlite - you should fill it record-by-record with full data, including omitted. So some class 'PersonalFinanceState' with default values for unset parameters suits great here.

  • any catalog with search - musical records, movies, stamps, food disposition in fridge...

  • some operations graphical primitives - read description of shapes (triangle, line, circle) and determine if two of them overlap.

  • tic-tac-toe of quattropoli engines. If you want to avoid clutchy GUI engines, implement only logic with coordinates as input and output. Or you could try to use Shoes too...

  • Midi music generation.

kirushik
A: 

I don't know if this will help, but have you taken a look at Ruby Koans?. If nothing else, I had some fun resolving the problems, they're good for a beginner. Plus it has some free form projects that you can do any way you like, especially the last (extra credit) project which is to implement the GREED game.

With regards to solutions, well, you could always look at the way I solved the problems at my github repo, but I dare say they're the best solutions. I'm sure there are many others available, just look at the people that forked the original repository.

RFelix
There's also the Code Katas (http://codekata.pragprog.com) which seem pretty cool, but they don't have any solutions. Maybe you can use them when your beginner reaches the intermediate level?
RFelix