Skip to main content
526 votes
21 answers
845k views

Do you know if there is a built-in function to build a dictionary from an arbitrary object? I'd like to do something like this: >>> class Foo: ... bar = 'hello' ... baz = 'world' ... ...
Julio César's user avatar
  • 13.4k
230 votes
5 answers
86k views

$0 is the variable for the top level Ruby program, but is there one for the current method?
salt.racer's user avatar
  • 22.5k
217 votes
8 answers
126k views

I was reading an article on TheServerSide on ployglot programming on the Java platform. Some comments in the article refer to metaprogramming as the ability to generate code (perhaps on the fly). Is ...
Parag's user avatar
  • 12.7k
183 votes
4 answers
119k views

How can I do what they are talking about here, but in Ruby? How would you do the function on an object? and how would you do a global function (see jetxee's answer on the post mentioned)? EXAMPLE ...
BuddyJoe's user avatar
  • 71.4k
181 votes
10 answers
84k views

I want to get into more template meta-programming. I know that SFINAE stands for "substitution failure is not an error." But can someone show me a good use for SFINAE?
rlbond's user avatar
  • 68.5k
179 votes
5 answers
83k views

I am aware of how to create getters and setters for properties whose names one already knows, by doing something like this: // A trivial example: function MyObject(val){ this.count = 0; this....
daiscog's user avatar
  • 12.2k
166 votes
4 answers
67k views

I would like to pass an argument(s) to a method being defined using define_method, how would I do that?
Sixty4Bit's user avatar
  • 13.5k
166 votes
21 answers
113k views

Being able to create and manipulate strings during compile-time in C++ has several useful applications. Although it is possible to create compile-time strings in C++, the process is very cumbersome, ...
void-pointer's user avatar
  • 15.1k
153 votes
9 answers
159k views

Can someone please tell me what the following snippet obj.send("#{method_name}") is and does?
Christian Bankester's user avatar
153 votes
5 answers
11k views

From something like this: print(get_indentation_level()) print(get_indentation_level()) print(get_indentation_level()) I would like to get something like this: 1 2 3 Can the code read ...
Fab von Bellingshausen's user avatar
148 votes
6 answers
38k views

Given a lambda, is it possible to figure out it's parameter type and return type? If yes, how? Basically, I want lambda_traits which can be used in following ways: auto lambda = [](int i) { return ...
Sarfaraz Nawaz's user avatar
132 votes
1 answer
18k views

Pony ORM does the nice trick of converting a generator expression into SQL. Example: >>> select(p for p in Person if p.name.startswith('Paul')) .order_by(Person.name)[:2] SELECT &...
Paulo Scardine's user avatar
131 votes
3 answers
61k views

I am trying to get a string name of a class from the class object itself. // For instance [NSArray className]; // @"NSArray" I have found object_getClassName(id obj) but that requires an instance be ...
Alex Wayne's user avatar
  • 188k
126 votes
8 answers
78k views

Static metaprogramming (aka "template metaprogramming") is a great C++ technique that allows the execution of programs at compile-time. A light bulb went off in my head as soon as I read this ...
jwfearn's user avatar
  • 29.8k
124 votes
13 answers
9k views

In a recent interview, I was asked a really strange question. The interviewer asked me how can I compute 1+2+3+...+1000 just using compiler features. This means that I am not allowed to write a ...
TonySalimi's user avatar
  • 8,503

15 30 50 per page
1
2 3 4 5
324