Hot answers tagged

5

This is a different sort of answer than what you may be hoping for, but I'd really recommend that you deepen your knowledge of Python first. Learn to be pythonic, learn its OOP aspects. Learn its dynamic aspects. Become a Python Wizard. The reason for this advice, since you are fairly new at this, is that there is a danger that you will try to learn too ...


4

During lecture, my students and I recreate Javascript objects in Ruby. In Javascript, these two lines are synonymous: config['indent'] = 2; config.indent = 2; Ruby doesn't support this duality natively, but metaprogramming makes it possible. We create a class AutoObject that internally stores a dictionary to hold all of the object's properties. Its ...


3

I'd recommend that you look into sinatra or one of the tutorials that are linked from the ruby docs. They also have a specific tutorial in the docs for moving to ruby from another language. The reason I'd recommend sinatra is because it is an intro to what ruby is mainly used for in the real world: Web Development. A huge part of ruby is ruby on rails. A ...


3

Personally, I'd introduce Sinatra first. Which one of these is going to be easier to explain? Sinatra's "Hello World" example... require 'sinatra' get '/' do 'Hello world!' end Or all the boilerplate that Rails generates... $ rails new commandsapp create create README.md create Rakefile create config.ru create .gitignore create Gemfile ...


2

The obvious introductory example would be re-implementing Module#attr_reader / Module#attr_writer / Module#attr_accessor, which after all are typically the first example of metaprogramming a Ruby programmer comes in contact with: module MyAttrAccessor def attr_reader(*attrs) attrs.each do |attr| define_method(attr) do p instance_variable_get(:"@#...


2

I think I can answer this via analogy with Python and a surface-level knowledge of Ruby and Sinatra, having skimmed the docs for the latter. From what I can tell the following holds true (although I'd gladly be corrected if it's too reductive): Sinatra : Ruby on Rails :: Flask : Django If you want a full framework for Ruby, you go with RoR; if for Python, ...


2

Perhaps I'm wrong, but your question (and your example) seems to imply that your intention is too "teach them Ruby". For beginners that seems backwards to me. My intention would be to teach them to "solve interesting problems". Once someone already knows "how to program" in some language it seems fine to teach them a (different) language. But focusing on ...


2

I almost always teach programming by connecting each component of programming with something in real life. For instance, when explaining variables, I ask the students to imagine them as boxes in which you put things, like food items or gifts or something similar. For methods, I ask them to think of their friends. For instance, there will be a 'rich' friend,...


2

Subroutines/methods are a way to reuse code. As is iteration (loops). They are also a way to document what code does. Therefore show how they can be used to reduce the amount of code: to make the program simpler, and to make it more readable. Note that there is often resistance as a new concept: as, temporarily, it does not make sense, so is not simpler. ...


1

Have them write up a straight class and document it. Here are some ideas. Complex Numbers: Create a class that spawns complex numbers and does their arithmetics. Throw exceptions where needed. Big Fraction: Create a class for extended-precision rational arithmetic. You will need +, -, * and /. Quaternions: These are used extensively in computer ...


1

A documentation system similar to Python's, where documentation isn't stored in the source text, but as dynamic data inside of instance variables of the documented objects themselves. This also allows you to talk about Ruby's object model, e.g. the fact that methods aren't objects and thus you can't store the documentation of a method inside the method, you ...


Only top voted, non community-wiki answers of a minimum length are eligible