sql
html
php
c
xml
mysql
android
regex
objective-c
visual-studio
multithreading
eclipse
silverlight
flash
facebook
oracle
apache
php5
api
jsp
You could pass an array with a single number, like [1], or a hash like {value: 1}. Less ugly than a string, as your number itself remains a number, but less overhead than a new class...
[1]
{value: 1}
Ruby will always pass-by-reference (because everything is an object) but Fixnum lacks any methods that allow you to mutate the value. See "void foo(int &x) -> Ruby? Passing integers by reference?" for more details.
You can either return a value that you then assign to your variable, like so:
a = 5 def do_something(value) return 1 #this could be more complicated and depend on the value passed in end a = do_something(a)
or you could wrap your value in an object such as a Hash and have it updated that way.
a = {:value => 5} def do_something(dict) dict[:value] = 1 end do_something(a) #now a[:value] is 1 outside the function
Hope this helps.
When I was building a game I had the same problem you have. There was a numeric score that represented how many zombies you've killed and I needed to manually keep it in sync between Player (that incremented the score), ScoreBar and ScoreScreen (that displayed the score). The solution I've found was creating a separate class for the score that will wrap the value and mutate it:
class Score def initialize(value = 0) @value = value end def increment @value += 1 end def to_i @value end def to_s @value.to_s end end