Ruby

1K

Solutions

4

Articles & Videos

1K

Contributors

Ruby is an open-source dynamic object-oriented interpreted language that supports multiple programming frameworks including functional, object oriented and imperative. It also has a dynamic type system and automatic memory management. Ruby focuses on simplicity and productivity. Ruby's market share spiked due to Ruby on Rails, a model-view-controller (MVC) framework for building web applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differently based on the default value of the type field!
0
Free Tool: SSL Checker
LVL 9
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below:
http://www.rubytips.org/2008/05/13/accessing-windows-api-from-ruby-using-win32api-library/
http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_windows.html

But all of these articles, tips don't mention how to process the returned pointer of a struct or memory block. As we known, standard DLL routine should return a code and return pointer/struct/memory block by function arguments, memory should free by claimer, so we can allocate memory in our codes and pass this pointer into DLL, the DLL routine save returned data into that pointer, after processed we need to free the allocated pointer ourselves. Anyway, the DLL author might not follow the General Programming Rules, or have some special reason, the DLL maybe return a pointer structure data directly instead of function arguments.

For example, if a definition like below:
typedef  struct Data {
    int len;
    int flag;
    char values[1000];
  } *Data;
  PData = *Data;

Open in new window

and the exports function of the DLL like below:
Data* GetData(int index, int flag); cdcel;

Open in new window


Win32API only provider a few data types like "0", "V", "I", "L", "P", other data types of other languages will mapping to these types, then we using "P" to receive the pointer data. unfortunately, we can't get the correct data by Win32API in Ruby via normally way:
require "Win32API"
getData = Win32API.new('filename.dll', 'GetData', ['I', 'I'], 'P');
pdata = getData.call(100, 10)

Open in new window

0
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between the two in order to give you a better idea of what they are in the hope that if you know a bit more about them you will begin to understand their respective uses. My feeling is that if you don't understand what you're doing or what you're using, you won't code as efficiently or as effectively.

Ruby contains these neat little things called a Lambda. It's actually a borrowed concept and name from Python, a language that has a lot of influence in Ruby's design.

These Lambda functions have different names in other languages, such as:

Lambda
Anonymous Function
Closure
They essentially name the same concept, so if you're coming from another language that has these, you already have a head start.

In Ruby, a Lambda is defined as follows,
x = lambda { return "ar har har har" }

Open in new window

If you're not new to Ruby, you've probably heard of procs. These are very similar to lambdas with very subtle, yet significant, differences. The most notable difference between a proc and a lambda is that returning from a proc will actually return from the method its defined within.  Example:
def a_meth
   proc = Proc.new{ return "blah" }
   proc.call
   return "not reached"
end

Open in new window


If you run this in IRB, you'll get "blah" returned instead of "not reached".  Now let's look at a similar method using a lambda:

Open in new window

0
I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to build a working project on a tight deadline.

This is how I did it.  I'll mention the specific books I used and why, but I don't think that's critical.  Just look at the process and then come up with something that works for you.

I started out by learning some Ruby first.  I think this is absolutely critical.  If you want to be good at Rails, you need to know Ruby.  If you have any programming experience (especially with any OO language), you can basically skim through an introduction on Ruby.

I used Programming Ruby in the pragmatic programmers series because I really like the pragmatic programmers series.  I was not disappointed by this book either.  I just skimmed through it in 2 afternoons, and then I referred to it several times as I started getting into Rails.

Another good route would be to look at one of the various online tutorials on Ruby.  I found this Introduction to Ruby tutorial is a good introduction and a very good reference if you quickly have to look up something.

If you don't have much programming experience I would recommend you start with Ruby in twenty minutes
3

Ruby

1K

Solutions

4

Articles & Videos

1K

Contributors

Ruby is an open-source dynamic object-oriented interpreted language that supports multiple programming frameworks including functional, object oriented and imperative. It also has a dynamic type system and automatic memory management. Ruby focuses on simplicity and productivity. Ruby's market share spiked due to Ruby on Rails, a model-view-controller (MVC) framework for building web applications.

Top Experts In
Ruby
<
Monthly
>