Possible Duplicate:
C# ?? operator in Ruby?
Is there a Ruby operator that does the same thing as C#'s ?? operator?
The ?? operator returns the left-hand operand if it is not null, or else it returns the right operand.
from http://msdn.microsoft.com/en-us/library/ms173224.aspx
Ruby is much much simpler than C++—it will spoil you rotten. Ruby is dynamically typed, rather than statically typed—the runtime does as much as possible at run-time. For example, you don't need to know what modules your Ruby program will “link to” (that is, load and use) or what methods it will call ahead of time.
Writing A Ruby Method From C A VALUE is a Ruby object. Now we need to attach this function to a Ruby class or module. You can create a new class or use an existing one. You can use the rb_define_method method to attach the C function to this module.
The original Ruby interpreter is often referred to as Matz's Ruby Interpreter or MRI. This implementation is written in C and uses its own Ruby-specific virtual machine. The standardized and retired Ruby 1.8 implementation was written in C, as a single-pass interpreted language.
This is how Ruby implements object-oriented code in C: a Ruby object is an allocated structure in memory that contains a table of instance variables and information about the class. The class itself is another object (an allocated structure in memory) that contains a table of the methods defined for that class.
The name of the operator is the null-coalescing operator. The original blog post I linked to that covered the differences in null coalescing between languages has been taken down. A newer comparison between C# and Ruby null coalescing can be found here.
In short, you can use ||
, as in:
a_or_b = (a || b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With