Posted to tcl by aspect at Tue Jun 09 12:15:30 GMT 2015view raw
- Index: modules/ooutil/ooutil.tcl
- ==================================================================
- --- modules/ooutil/ooutil.tcl
- +++ modules/ooutil/ooutil.tcl
- @@ -89,17 +89,21 @@
- }
- # Build this *almost* like a class method, but with extra care to avoid nuking
- # the existing method.
- oo::class create oo::class.Delegate {
- - method create {name {script ""}} {
- + method create {name args} {
- + if {![string match ::* $name]} {
- + set ns [uplevel 1 {namespace current}]
- + if {$ns eq "::"} {set ns ""}
- + set name ${ns}::${name}
- + }
- if {[string match *.Delegate $name]} {
- - return [next $name $script]
- + return [next $name {*}$args]
- }
- - set cls [next $name]
- - set delegate [oo::class create $cls.Delegate]
- - uplevel 1 [::list oo::define $cls $script]
- + set delegate [oo::class create $name.Delegate]
- + set cls [next $name {*}$args]
- set superdelegates [list $delegate]
- foreach c [info class superclass $cls] {
- set d $c.Delegate
- if {[info object isa object $d] && [info object isa class $d]} {
- lappend superdelegates $d
- Index: modules/ooutil/ooutil.test
- ==================================================================
- --- modules/ooutil/ooutil.test
- +++ modules/ooutil/ooutil.test
- @@ -30,13 +30,41 @@
- }
- } -cleanup {
- namespace delete ooutiltest
- rename animal {}
- } -result {::ooutiltest::dog}
- +
- +test ooutil-classmethod-1 {test ooutil classmethod} -setup {
- + oo::class create ActiveRecord {
- + classmethod find args { puts "[self] called with arguments: $args" }
- + }
- + oo::class create Table {
- + superclass ActiveRecord
- + }
- +} -body {
- + Table find foo bar
- +} -cleanup {
- + rename ActiveRecord {}
- +} -output "::Table called with arguments: foo bar\n"
- +
- +test ooutil-classmethod-2 {test ooutil classmethod in namespace} -setup {
- + namespace eval testns {
- + oo::class create ActiveRecord {
- + classmethod find args { puts "[self] called with arguments: $args" }
- + }
- + oo::class create Table {
- + superclass ActiveRecord
- + }
- + }
- +} -body {
- + testns::Table find foo bar
- +} -cleanup {
- + namespace delete testns
- +} -output "::testns::Table called with arguments: foo bar\n"
- +
- # Test properties
- -
- oo::class create foo {
- property color blue
- constructor args {
- my InitializePublic