words function
words: func [ "Returns block of object words, excluding self directive." object [object!] "Target object." ][ next first object ]
12390 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
words: func [ "Returns block of object words, excluding self directive." object [object!] "Target object." ][ next first object ]
remove-words: func [ "Returns a copy of the object with the specified words removed." object [object!] words [word! block!] "The word, or words, to remove" /local spec ][ spec: load obj-spec object foreach word compose [(words)] [ remove/part find spec to set-word! word 2 ] make object! spec ]
/** * Singleton Repository * @param string $class PHP Class Name * @param string $id Optional Object ID * @return reference Reference to existing Object */ function &Singleton($class, $id='') { static $singleton = array(); if (!array_key_exists($class.$id, $singleton)) $singleton[$class.$id] = &new $class(); $reference = &$singleton[$class.$id]; return $reference; }
# first call: create object $site_user=&Singleton('Student'); $site_user->Drink_Beer(5); # second call: get a reference $current_user=&Singleton('Student'); echo $current_user->Show_Beers_Counter(); #will be 5 #Two different objects $one=&Singleton('Some_Class','one'); $two=&Singleton('Some_Class','two');
package thing; use strict; sub new { my %self; my ($class,@rest) = @_; unless ($#rest%2) { die "Odd parameter count\n"} for (my $k=0; $k<@rest; $k+=2) { my $wotsit = lc($rest[$k]); $wotsit =~ s/-//; $self{$wotsit} = $rest[$k+1]; } bless \%self,$class; } sub AUTOLOAD { my ($where,$val) = @_; our $AUTOLOAD; $AUTOLOAD =~ s/.*://; my ($dirn,$what) = ($AUTOLOAD =~ /(...)(.*)/); if ($dirn eq "get") { return $$where{lc($what)}; } elsif ($dirn eq "set") { $$where{lc($what)} = $val; } return 1; } 1;
use thing $house = new thing("type","building","rooms",12,"foundations", "yes"); print $house -> gettype(); $house -> settype("tree"); print " " . $house -> gettype();