I was trying to understand this call:
deprecate :new_record?, :new?
which uses this deprecate method:
def deprecate(old_method, new_method)
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{old_method}(*args, &block)
warn "\#{self.class}##{old_method} is deprecated," +
"use \#{self.class}##{...
As I have become more and more comfortable using metaprogramming techniques I have found more and more applications for metaprogramming as well. I'm working now on a little project in which I am creating classes and instances of these classes on the fly and I'm wondering if I have taken metaprogramming too far? Is there such a thing as...
I have a smart pointer type, and would like to construct an object that takes a pointer of that type and a count (dynamically calculated at runtime) and allocates enough memory from the stack to hold that many instances of the object the smart pointer points to. I can't seem to find quite the right syntax to achieve this; is it possible?...
First time poster, be gentle!
I have a C++ snippet below with a run-time for loop,
for(int i = 0; i < I; i++)
for (int j = 0; j < J; j++)
A( row(i,j), column(i,j) ) = f(i,j);
The snippet is called repeatedly. The loop bounds 'I' and 'J' are known at compile time (I/J are the order of 2 to 10). I would like to unroll the loop...
Xcode allows you to create automated scripts for performing repetitive tasks. What scripts have you written to speed up development?
...
How to generate fusion::vector from mpl::vector?
How to generate mpl::vector from fusion::vector?
BOOST_MPL_ASSERT((is_same<
fusion::vector<int, char>,
generate_fusion_vector<mpl::vector<int, char> >::type >));
BOOST_MPL_ASSERT((is_same<
mpl::vector<int, char>,
gen...
I am making a framework where objects should be created a according to a predefined XML file.
For example, if in the xml file the following occurs:
<type name="man">
<property name="name" type="string">
<property name="height" type="int">
<property name="age" type="int">
<property name="profession" type="string" value="...
Hi,
In a Grails application I would like to add a foo() method to all my controller classes. I know that I can do this inside a plugin's doWithDynamicMethods closure using code like:
application.controllerClasses.toList()*.metaClass*.foo = { println 'foo called' }
However, I don't want to create a plugin just for this purpose. Is the...
Hi,
In a Grails application I'm looking for some way to pass data from a controller action to a filter that runs after the action. I was thinking of something like:
class MyController {
def myAction = {
render(view:"myView", model:[key: "value"])
passData {
// Do some processing here
name = ...
I'm curious to find out if and when C++ meta templates are a good design choice for systems small to large. I understand that they increase your build time in order to speed up your execution time. However, I've heard that the meta template code is inherently hard to understand by many developers, which could be a problem for a large gro...
What I'm trying to find out is whether there is some sort of equivalence to what I see in Groovy as ExpandoMetaClasses. I've been reading about Open Classes but I can't quite see what level of scoping Ruby allows of the class modifications.
Borrowing an example from the blog above, in Groovy, I could modify Java's String class and add ...
Let's say I want some instance of String behave differently from other, "normal" instances - for example cancel the effect of the "upcase" method. I do the following:
class String
def foo
def self.upcase
self
end
self
end
end
It seems to work fine, and the way I need it:
puts "bar".upcase #=> "BAR"
puts "bar".fo...
Are there any tools out there that let you model how a class (or a class hierarchy) can change at runtime? For example, if I have a given number of mixin classes that will be combined at runtime and I don't know which ones will be combined until the program runs, how do you go about diagramming that type of runtime behavior?
Here's a be...
In general, how can I get a reference to an object whose name I have in a string?
More specifically, I have a list of the parameter names (the member variables - built dynamically so I can't refer to them directly).
Each parameter is an object that also has an from_s method.
I want to do something like the following (which of course do...
I have the following two projects in in Flex Builder 3:
One AS3 library project (generates a SWC file)
One Flex application project (MXML Application)
The MXML Application references to the AS3 library project (Flex build path). So far, so good. I now want to run code automatically when an application uses the AS3 library. The [mixin...
I have the following code:
template <int size>
inline uint hashfn( const char* pStr )
{
uint result = *pStr;
switch ( size )
{
case 10:
result *= 4;
result += *pStr;
case 9:
result *= 4;
result += *pStr;
...
...
case 2:
result *= 4;
result += *p...
I would like to add some methods to a class definition at runtime. However, when running the following code, I get some surprising (to me) results.
test.py
class klass(object):
pass
for i in [1,2]:
def f(self):
print(i)
setattr(klass, 'f' + str(i), f)
I get the following when testing on the command line:
>>> impor...
Assume I have a family of related modules:
module Has_Chocolate
def has_chocolate?
true
end
end
module Has_Cake
def has_cake?
true
end
end
.
.
.
How would I construct a template module Has_*Something* where Something would be a parameter to the module?
...
Hello!
Consider the following code:
def create_class(class_name, superclass, &block)
klass = Class.new superclass, &block
Object.const_set class_name, klass
end
After I do:
create_class('User', ActiveRecord::Base)
the following is ok:
Object.send(:remove_const, :User)
but this:
Object.remove_const :User
results in th...
Another project from Jetbrains, their new issue tracker Charisma was written entirely in MPS. Is the concept useful/practical, or is it too soon?
...